web.xml 通过contextConfigLocation配置spring 的方式
SSI框架配置文件路径问题:
struts2的 1个+N个? 路径:src+src(可配置)????? 名称: struts.xml? + N
spring 的 1个?????????? 路径: src????????????????????????? 名称: applicationContext.xml
ibatis 的 1个+N个? 路径: src+src(可配置)???? 名称: SqlMapConfig.xml + N
部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下
spring的 配置文件在启动时,加载的是web-info目录下的applicationContext.xml,
运行时使用的是web-info/classes目录下的applicationContext.xml。
配置web.xml使这2个路径一致:
<context-param>
? <param-name>contextConfigLocation</param-name>
? <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
多个配置文件的加载
<context-param>
??????? <param-name>contextConfigLocation</param-name>
??????? <param-value>
??????????? classpath*:conf/spring/applicationContext_core*.xml,
??????????? classpath*:conf/spring/applicationContext_dict*.xml,
??????????? classpath*:conf/spring/applicationContext_hibernate.xml,
??????????? classpath*:conf/spring/applicationContext_staff*.xml,
??????????? classpath*:conf/spring/applicationContext_security.xml
??????????? classpath*:conf/spring/applicationContext_modules*.xml
??????????? classpath*:conf/spring/applicationContext_cti*.xml
??????????? classpath*:conf/spring/applicationContext_apm*.xml
??????? </param-value>
??? </context-param>
contextConfigLocation 参数定义了要装入的 Spring 配置文件。
首先与Spring相关的配置文件必须要以"applicationContext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。
还有最好把所有Spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。
在web.xml中的配置如下:
Xml代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:**/applicationContext-*.xml</param-value>
</context-param>
"**/"表示的是任意目录;
"**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。
你自己可以根据需要修改。最好把所有Spring配置文件都放在一个统一的目录下,如:
<!-- Spring 的配置 -->
<context-param>
? <param-name>contextConfigLocation</param-name>
? <param-value>classpath:/spring/applicationContext-*.xml</param-value>
</context-param>
web.xml中classpath:和classpath*:, 有什么区别?
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找
详细解决方案
web.xml 经过contextConfigLocation配置spring 的方式
热度:291 发布时间:2012-08-29 08:40:14.0
相关解决方案
- Spring MVC开发模式,怎么取得新增的id
- spring 表单对象绑定有关问题 String与Long的转换
- spring+quartz定时器有关问题
- spring @Scope("prototype")注解更新有关问题,寻求帮助
- Spring MVC是不是可以完全取代Struts
- spring+quartz的错误,不能正常启动
- Spring 中 packagesToScan有关问题
- Spring MVC中点击旋钮没反应
- spring 事务 aop transactionManager,该怎么解决
- Struts2+Spring+JPA+FREEMARKER 登录程序异常
- 求SSM分页 struts +spring+mybatis 给小弟我发个学习学习吧 多谢大神们
- spring placeholderConfig的有关问题
- spring 事宜 aop transactionManager
- Spring 和 hibernate如何配置事物
- hibernate与此同时使用多数据源?spring+hibernate
- Spring 动态代理,该怎么解决
- java spring mvc,该怎么解决
- spring mvc 接收对象数组解决办法
- Spring Data 的有关问题
- spring mvc3 使用jackson返回json时候无限循环
- struts+spring+hibernate 开发,在action层调用service层接口,结果替null 注入失败,需高手帮忙
- 生手求教,dwr+struts+spring 页面跳提示框error
- spring IOC 原理解决方法
- uploadify3.1下传 spring+struts2+hibernate框架中取值的有关问题
- tomcat起步后spring自动关闭 Closing Spring root WebApplicationContext
- spring 事务配置不回滚的有关问题。
- spring mvc施用得广泛么
- Spring Quartz定时任务怎么获得ServletContext对象
- Spring MVC中的SimpleControllerHandlerAdapters是作什么用的?该怎么解决
- Spring 的小疑点