I have two Spring Projects, Backend and Frontend. The Upgrade of backend was trouble-free (Spring 4.1.2.RELEASE). While deploying the frontend i have this Exception:
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]
This is the WebAppInitializer for Frontend:
@Configuration
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { AppConfig.class };
}
.....
Appconfig is in backend project and looks like this:
@Import(DataConfig.class)
@Configuration
public class AppConfig {
...
}
The missing property file is used in DataConfig which is imported here:
@PropertySource("jdbc.properties")
@Configuration
public class DataConfig {
...
}
Why could not the property file not be found?
EDIT: Jar structure of the backend:
War structure of the frontend:
Tell the configuration class that your properties is in the classpath. Otherwise, it will look in the Servlet context by default since it's a web context.
@PropertySource("classpath:jdbc.properties")
Check jdbc.properties
is in the root of your classpath. If that's not the problem I'd need more details on your problem, like what's your folder structure and if you compile-package to a war.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.