java - 无法从@PropertySource读取配置文件

标签 java spring ubuntu gradle annotations

我正在尝试将下一个注释应用于配置类:

@Configuration
@EnableCaching
@ComponentScan({ "com.foo.*" })
@PropertySources({
    @PropertySource("classpath:foo.properties"),
    @PropertySource(value = "file:${catalina.home}/conf/foo.properties", ignoreResourceNotFound = true),
})

但我遇到以下异常:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.company.config.CoreConfig]; nested exception is java.io.FileNotFoundException: class path resource [foo.properties] cannot be opened because it does not exist

我尝试在 Google 上查找此错误,并发现了许多相关内容,但没有任何内容可以帮助我。

文件路径为:

/home/me/apache-tomcat-8.0.36/conf

最佳答案

我通过删除这一行解决了这个问题:

@PropertySource("classpath:foo.properties"),

关于java - 无法从@PropertySource读取配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44435605/

相关文章:

java - Spring安全吃Angularjs POST请求

java - "java.lang.IllegalArgumentException: Not a managed type ..."当实体类和Spring数据存储库在同一个包中时

linux - Ubuntu:如何在 shell 中输入目录

java - 无法解析,在索引 23 处找到未解析的文本

java - 连接到 repo.maven.apache.org :443 failed

java - 使用 Java 泛型为实体实现转换器

ubuntu - 将虚拟机从 KVM 迁移到 Openstack

java - 第二次身份验证失败 Java Mail API

java - 将查询生成的 excel 文件下载到数据库

java - 无法在 Tomcat 7 ubuntu 服务器上运行 .jsp 文件