首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring @PropertySource不存在,无法打开

Spring @PropertySource不存在,无法打开
EN

Stack Overflow用户
提问于 2019-02-19 19:17:14
回答 2查看 3.9K关注 0票数 1

我有一个简单的spring应用程序。Spring版本为3.2.16.RELEASE

项目结构为:

应用程序类如下所示:

代码语言:javascript
复制
@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();
    }
}

当我尝试运行它时,我有:

代码语言:javascript
复制
Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist

我试过了:

代码语言:javascript
复制
@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项目结构正常。

有什么想法可能是错的吗?我错过了什么吗?

谢谢你的建议!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-19 19:43:00

尝试添加绝对路径文件位置@PropertySource("file:/root/.../application.properties")

票数 1
EN

Stack Overflow用户

发布于 2021-08-31 17:27:30

请尝试添加org.springframework.boot spring-boot-configuration-processor

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54765039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档