akc*_*soy 1 java spring spring-mvc maven
我有两个Spring项目,Backend和Frontend.后端的升级没有问题(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]
Run Code Online (Sandbox Code Playgroud)
这是Frontend的WebAppInitializer:
@Configuration
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { AppConfig.class };
}
.....
Run Code Online (Sandbox Code Playgroud)
Appconfig位于后端项目中,如下所示:
@Import(DataConfig.class)
@Configuration
public class AppConfig {
...
}
Run Code Online (Sandbox Code Playgroud)
缺少的属性文件在DataConfig中使用,在此处导入:
@PropertySource("jdbc.properties")
@Configuration
public class DataConfig {
...
}
Run Code Online (Sandbox Code Playgroud)
为什么找不到属性文件?
编辑:后端的Jar结构:
前端的战争结构:
Kha*_*lid 10
告诉配置类您的属性在类路径中.否则,默认情况下它将在Servlet上下文中查找,因为它是一个Web上下文.
@PropertySource("classpath:jdbc.properties")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7412 次 |
| 最近记录: |