`

SSH的两种组合配置方法

    博客分类:
  • SSH
阅读更多

      既可以使用 web.xml 来使 Web 容器加载 Spring,也可以通过 struts-config.xml 来使 Web 容器加载 Spring。

1、使用 web.xml 来使 Web 容器加载 Spring

 web.xml :
通过: 

<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener-->

 

 

 

 

 

或:

<servlet>
      <servlet-name>SpringContextServlet</servlet-name>
      <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
</servlet>

 
Web 容器会自动加载 /WEB-INF/applicationContext.xml 初始化 ApplicationContex t实例;
也可以通过
  

 <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext-*.xml</param-value>
 </context-param>

 
使 Web 容器加载指定名称路径的 Spring 配置文件。

 

 

2、通过 struts-config.xml 来使 Web 容器加载 Spring

struts-config.xml
通过
   

 <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation" 
            value="/WEB-INF/applicationContext.xml,
                   /WEB-INF/action-servlet.xml"/>
</plug-in>

 
来加载 Spring 配置文件。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics