applicationContext.xml 配置的两种方法
2017-12-23 13:58
274 查看
Spring 项目中 applicationContext.xml 配置有两种方法。两种不能同时配置,不然会文件内配置的bean会被初始化2次
参考: https://www.cnblogs.com/caryfang/p/5675178.html
第一种全局配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
第二种在DispatcherServlet中已参数的形式配置
<servlet>
<servlet-name>springmvc-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc-web</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
参考: https://www.cnblogs.com/caryfang/p/5675178.html
第一种全局配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
第二种在DispatcherServlet中已参数的形式配置
<servlet>
<servlet-name>springmvc-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc-web</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
相关文章推荐
- Spring ClassPathXmlApplicationContext和FileSystemXmlApplicationContext读取配置文件的方法
- 在struts2.0框架中,多struts.xml与多applicationContext.xml配置的方法
- SSH框架整合时applicationContext.xml的配置,关于在main方法中测试注意的事项
- SSH读取applicationContext.xml配置文件测试hibernate方法
- Spring配置文件applicationContext.xml的两种拆分方式
- 读取配置applicationContext.xml 的5种方法
- ApplicationContext.xml的两种配置方式
- applicationContext.xml 配置方法
- Spring配置文件applicationContext.xml的两种拆分方式
- spring配置文件applicationContext.xml不能自动提示的解决方法
- spring配置文件applicationContext.xml不能提示的解决方法
- spring mybatis 框架集成之applicationContext.xml配置方法
- java中读取配置文件的方法fileSystemXmlapplicationContext与classPathXmlApplicationContext
- SSH里applicationContext.xml中配置pojo映射文件的方法
- 读取Spring的配置文件applicationContext.xml几种方法
- 在struts2.0框架中,多struts.xml与多applicationContext.xml配置的方法
- [学习笔记]在struts2.0框架中,多struts.xml与多applicationContext.xml配置的方法
- applicationContext.xml 配置文件的存放位置
- Spring的applicationContext.xml配置
- Spring配置文件总结-applicationContext.xml