博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ssi配置
阅读量:6910 次
发布时间:2019-06-27

本文共 3064 字,大约阅读时间需要 10 分钟。

                ssi配置

最近公司用到了ssi,给大家介绍下,和ssm不同他是4层逻辑。。。

添加配置文件

   我们首先从web.xml文件说起 

   web.xml加载过程:

   1 启动WEB项目的时候,容器(如:Toat)会读他的配置文件web.xml读两个节点
         <listener></listener>和<contt-param></context-param>
    2 紧接着,容器创建一个ServletContext(上下文) 这个WEB项目所有部分都将共享这个上下文
    3 容器将<context-param></context-param>转化为键值对并交给ServletContext
    4 容器创建<listener></listener>中的类的实例,即创建监听
    5 在监听中会有contextInitialized(ServletContextEvent args)初始化方法,在这个方法中获得:
              ServletContext = ServletContextEvent.getServletContext();   
              context-param的值 = ServletContext.getInitParameter("context-param的键"); 

     web.xml节点加载顺序

     节点的加载顺序与它们在web.xml文件中的先后顺序无关。即不会因为filter写在listener的前面而会先加载filter最终得出的结论是:listener->filter->servlet
     同时还存在着这样一种配置节点:context-param,它用于向 ServletContext 提供键值对,即应用程序上下文信息。我们的 listener, filter 等在初始化时会用到这些上下文 的信息,那么context-param 配置节是不是应该写在 listener 配置节前呢?实际上 context-param 配置节可写在任意位置,因此真正的加载顺序为:
context-param -> listener -> filter -> servlet
     加载spring
     <listener>  
             <listener-class>  
               org.springframework.web.context.ContextLoaderListener   
            </listener-class>  
       </listener>
     最终结论:

     web.xml 的加载顺序是:[context-param -> listener -> filter -> servlet -> spring] ,而同类型节点之间的实际程序调用的时候的顺序是根据对应的 mapping 的顺序进行调  用的。

    打开web.xml文件,根据实际需要添加如下内容

webAppRootKey
/WEB-INF/log4j.properties
contextConfigLocation
/WEB-INF/beans.xml
org.springframework.web.util.Log4jConfigListener
org.springframework.web.context.ContextLoaderListener

在这说说SSI整合时的一些配置文件:

 1,contextConfigLocation:Spring容器启动时需要加载Spring的配置文件。默认是/WEB-INF目录下的applicationContext.xml文件

   当然也可以放在classpath下,可以包括多个spring配置文件,这就得依靠contextConfigLocation

 

contextConfigLocation
/WEB-INF/beans.xml

如果web.xml中没有配置context-param,spring的配置就像如上这段代码示例一下,自动去WEB-INF目录下寻找applicationContext.xml。此时,如果你修改applicationContext.xml的名称,或者移除它,再启动服务器,你会得到如下异常信息:

1.nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

这证实了其默认配置。默认配置情况下spring只会去WEB-INF目录下寻找配置文件,而不会去classpath下寻找。 

如果我们不想将配置文件放在WEB-INF目录下呢?开发中经常在src下面创建一个config目录,用于存放配置文件。此时,对应的param-value改为:classpath:config/applicationContext.xml。
一定要加上classpath,这告诉spring去classes目录下的config目录下面寻找配置文件。
2,如何启动Spring容器

两种方法,一种以listener启动  一种以load-on-startup Servlet。

org.springframework.web.context.ContextLoaderListener

第二种

 
context
 
org.springframework.web.context.ContextLoaderServlet
 
1
 

 3,整合Struts2

   

struts2
org.apache.struts2.diser.ng.filter.StrutsPrepareAndExeeFilter
struts2
/*

4,Spring整合ibatis配置文件

  

classpath:SqlMapConfig.xml

5,Struts.xml

constant配置struts的常量(也可在struts.properties)文件中配置,将struts的对象工厂托由spring管理。

转载于:https://www.cnblogs.com/tongyl/p/6826242.html

你可能感兴趣的文章
oracle数据库导入导出命令!
查看>>
zoj 1610 Count the Colors 线段树区间更新/暴力
查看>>
android解决内存溢出的问题(没有从根本上解决)
查看>>
我心中想念那位偷吃玉米的老朋友
查看>>
“Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED”
查看>>
Kryo 为什么比 Hessian 快
查看>>
使用svn hooks 脚本post-commit时遇到的故障
查看>>
Android.mk 文件语法详解
查看>>
ThreadPool.QueueUserWorkItem的性能问题
查看>>
解读ASP.NET 5 & MVC6系列(11):Routing路由
查看>>
机器学习算法一览图
查看>>
识别出脸部以及给脸部打马赛克
查看>>
[转载]git 忽略某些文件
查看>>
jQuery 效果 - 隐藏和显示
查看>>
正则表达式的使用
查看>>
Android复制iPhone日期和时间选择器
查看>>
[C语言]进阶|指针与字符串
查看>>
检测ORACLE方法汇总数据块损坏
查看>>
Binary Tree Maximum Path Sum [leetcode] dp
查看>>
Xamarin.Android开发实践(八)
查看>>