我有一个简单的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")还有其他的..。
资源文件夹已标记为资源根目录...Intellij项目结构正常。
有什么想法可能是错的吗?我错过了什么吗?
谢谢你的建议!
发布于 2019-02-19 19:43:00
尝试添加绝对路径文件位置@PropertySource("file:/root/.../application.properties")
发布于 2021-08-31 17:27:30
请尝试添加org.springframework.boot spring-boot-configuration-processor。
https://stackoverflow.com/questions/54765039
复制相似问题