我有简单的spring应用程序。
Spring
的版本为3.2.16.RELEASE
。
项目结构为:
应用程序类如下:
@Configuration
@ComponentScan(basePackages = "ua.xxxx.spring.hometask")
@PropertySource(value = "classpath:application.properties")
public class Application {
public static void main(final String[] args) {
final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
final SpringHomeTaskConsoleUI consoleUI = context.getBean(SpringHomeTaskConsoleUI.class);
consoleUI.run();
}
}
当我尝试运行它时,我有:
Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
我正在尝试:
@PropertySource(value = "classpath*:application.properties")
@PropertySource(value = "classpath:/application.properties")
@PropertySource(value = "classpath:src/main/resources/application.properties")
@PropertySource(value = "classpath*:src/main/application.properties")
@PropertySource(value = "classpath:application.properties")
@PropertySource(value = "application.properties")
@PropertySource(value = "src/main/application.properties")
和其他...
Resources文件夹被标记为资源根目录... Intellij项目结构还可以。
任何想法可能有什么问题? 我错过了什么吗?
多谢指教!
答案 0 :(得分:1)
尝试添加绝对路径文件位置@PropertySource(“ file:/ root /.../ application.properties”)