问题产生:
前面讲过了Maven建立了依赖关系,把系统分割成了若干个jar/war包.
我建的依赖关系大致是war包中包含n个依赖的jar包,依赖层级如下:
order-war (html/template)
--order (action)
---- service (service/dao)
------ common /util
配置文件xml/properties分布在各个jar包中(保持应用之间相对独立)。
问题产生于:把原有的项目直接拉过来,打包、部署、启动就报错,applicationContext.xml找不到。很明显是读取不到jar包中的配置文件。
解决办法:
1,classpath:applicationContext.xml改为classpath*:applicationContext.xml
这么写也是一样的效果:classpath*:/applicationContext.xml
2,在applicationContext.xml引用其它的配置文件:
如果在同一个jar包这么写,
<import resource="classpath:/applicationContext-action.xml" />
要导入其它jar包中的配置文件,这么写
<import resource="classpath*:/applicationContext-service.xml" />
就这么简单,重新打包、部署、启动成功。
在浏览器中打开 http://127.0.0.1:8080/portal/index.htm
成功
3,classpath两种用法:
classpath*:applicationContext.xml会加入本项目及所有jar包根目录下的applicationContext.xml文件,跨jar包依赖时使用
classpath:applicationContext.xml只加入本项目根目录下的applicationContext.xml文件,不依赖其它jar包的配置文件时推荐这样写,以避免冲突。
分享到:
相关推荐
赠送Maven依赖信息文件:spring-messaging-4.3.12.RELEASE.pom; 包含翻译后的API文档:spring-messaging-4.3.12.RELEASE-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.springframework:spring-...
赠送Maven依赖信息文件:spring-beans-5.2.0.RELEASE.pom; 包含翻译后的API文档:spring-beans-5.2.0.RELEASE-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.springframework:spring-beans:5.2.0....
springmvc + spring + mybatis + maven整合配置文件
使用eclipse整合maven时所需要使用的配置文件;只需修改文件中的本地仓库路径即可完成整合,java初学者必选。
赠送Maven依赖信息文件:spring-test-5.3.15.pom; 包含翻译后的API文档:spring-test-5.3.15-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.springframework:spring-test:5.3.15; 标签:spring、...
Maven依赖:【***.jar Maven依赖信息(可用于项目pom.xml).txt】 Gradle依赖:【***.jar Gradle依赖信息(可用于项目build.gradle).txt】 源代码下载地址:【***-sources.jar下载地址(官方地址+国内镜像地址).txt】...
1.例子中还说明了配置文件放在maven的src/main/java下与放在第二个src下的main目录下的不同结果及加载方式:AppTest.java文件 2.列出配置文件的加载方式 a.通过spring-test的注解方式加载配置文件:AppTest2.java b....
赠送Maven依赖信息文件:spring-security-core-5.3.9.RELEASE.pom; 包含翻译后的API文档:spring-security-core-5.3.9.RELEASE-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework.security:...
Maven依赖:【***.jar Maven依赖信息(可用于项目pom.xml).txt】 Gradle依赖:【***.jar Gradle依赖信息(可用于项目build.gradle).txt】 源代码下载地址:【***-sources.jar下载地址(官方地址+国内镜像地址).txt】...
赠送Maven依赖信息文件:spring-security-crypto-5.5.2.pom; 包含翻译后的API文档:spring-security-crypto-5.5.2-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework.security:spring-security-...
赠送Maven依赖信息文件:spring-data-keyvalue-2.3.9.RELEASE.pom; 包含翻译后的API文档:spring-data-keyvalue-2.3.9.RELEASE-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework.data:spring-...
赠送Maven依赖信息文件:spring-context-support-1.0.10.pom; 包含翻译后的API文档:spring-context-support-1.0.10-javadoc-API文档-中文(简体)版.zip; Maven坐标:...
赠送Maven依赖信息文件:spring-aop-5.0.10.RELEASE.pom; 包含翻译后的API文档:spring-aop-5.0.10.RELEASE-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework:spring-aop:5.0.10.RELEASE; 标签...
赠送Maven依赖信息文件:spring-boot-configuration-processor-2.3.12.RELEASE.pom; 包含翻译后的API文档:spring-boot-configuration-processor-2.3.12.RELEASE-javadoc-API文档-中文(简体)版.zip; Maven坐标:...
赠送Maven依赖信息文件:spring-beans-5.0.10.RELEASE.pom; 包含翻译后的API文档:spring-beans-5.0.10.RELEASE-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework:spring-beans:5.0.10.RELEASE...
Maven配置文件Maven配置文件
配置服务端所需要的jar文件,包括commons-logging commons-beanutils commons-lang ezmorph json-lib-2.4-jdk15 commons-collections-3.2.1。
Maven依赖:【***.jar Maven依赖信息(可用于项目pom.xml).txt】 Gradle依赖:【***.jar Gradle依赖信息(可用于项目build.gradle).txt】 源代码下载地址:【***-sources.jar下载地址(官方地址+国内镜像地址).txt】...
赠送Maven依赖信息文件:spring-boot-autoconfigure-2.0.6.RELEASE.pom; 包含翻译后的API文档:spring-boot-autoconfigure-2.0.6.RELEASE-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.spring...
赠送Maven依赖信息文件:spring-data-keyvalue-2.5.5.pom; 包含翻译后的API文档:spring-data-keyvalue-2.5.5-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework.data:spring-data-keyvalue:...