【发布时间】:2015-01-20 00:38:44
【问题描述】:
我有两个 Spring 项目,后端和前端。后端升级没有问题(Spring 4.1.2.RELEASE)。在部署前端时,我有这个异常:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [acn.spring.config.AppConfig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:489)
....
Caused by:
java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
这是前端的 WebAppInitializer:
@Configuration
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { AppConfig.class };
}
.....
Appconfig 在后端项目中,如下所示:
@Import(DataConfig.class)
@Configuration
public class AppConfig {
...
}
在此处导入的 DataConfig 中使用了缺失的属性文件:
@PropertySource("jdbc.properties")
@Configuration
public class DataConfig {
...
}
为什么找不到属性文件?
编辑:后端的 Jar 结构:
- 元信息
- 清单.MF
- 行家
- mySourcePackages 结构
- jdbc.properties
前端的战争结构:
- 元信息
- 清单.MF
- 行家
- 资源
- WEB-INF
- 类
- mySourcePackages 结构
- jsp
- 库
- 包括 backend.jar 在内的所有 jars
- 类
【问题讨论】:
标签: java spring maven spring-mvc