Java 在Spring PropertySource中找不到属性

Java 在Spring PropertySource中找不到属性,java,spring,properties,annotations,filenotfoundexception,Java,Spring,Properties,Annotations,Filenotfoundexception,配置 道具位置 @Configuration @PropertySources({ @PropertySource("classpath*:properties/test-database.properties") }) public class DataSourceConfiguration {//... } D:\Projects\opti\dao\src\main\resources标记为资源文件夹。考虑到问题的细节,您的问题还不清楚,但是@PropertySource的一个典型

配置

道具位置

@Configuration
@PropertySources({
    @PropertySource("classpath*:properties/test-database.properties")
})
public class DataSourceConfiguration {//...
}

D:\Projects\opti\dao\src\main\resources标记为资源文件夹。

考虑到问题的细节,您的问题还不清楚,但是@PropertySource的一个典型问题是您配置了一个Springbean来管理属性。在过去,xml是配置Spring的最佳方式,您使用了一个名称空间配置来配置Springbean,以便在bean中使用proeprites,主要是@Value。在java配置中,为了实现相同的行为,您已经配置了一个类似belove的bean:

D:\Projects\opti\dao\src\main\resources\properties\test-database.properties

我希望这可以帮助您

避免此类问题问题问题是在VM参数中设置jboss.server.config.dir,如下所示:

@Bean
public static PlaceholderConfigurerSupport propertyPlaceholderConfigurer() {
       return new PropertySourcesPlaceholderConfigurer();
   }
您可以这样设置PropertySource:

-Djboss.server.config.dir="[jboss_repository]/server/[default-all-standard-standalone]/conf" –server
或者您这样设置您的属性

@Configuration
@PropertySource("file:${jboss.server.config.dir}/file.properties")

执行时,属性将从位于类路径根中的应用程序.properties
文件导入

这很奇怪,但是对于Guava Resources.getResource(“/properties/test database.properties”)文件找不到。我想,这是因为gradle,需要思考。这很清楚,因为with/you有一个相对的文件路径,而不带/像这样:Resources.getResource(“properties/test database.properties”)
@PropertySource(value = "classpath:application.properties")