SSH整合,在Struts整合到Spring之前使用Spring的容器对象操作



SSH整合,在Struts整合到Spring之前使用Spring的容器对象操作

1.在web.xml中初始化spring的配置文件
<!– 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 –>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!– 对Spring容器进行实例化 –>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.在action中使用spring的容器对象
WebApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());

http://blog.sina.com.cn/s/blog_976e495701013ifl.html