简体   繁体   English

Spring PropertySource找不到的属性

[英]Properties not found with Spring PropertySource

Config 配置

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

Prop location 支柱位置

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

D:\\Projects\\opti\\dao\\src\\main\\resources marked as resource folder. D:\\ Projects \\ opti \\ dao \\ src \\ main \\ resources标记为资源文件夹。

It isn't clear well the your problem considering the details of your question, but a typical problem whit @PropertySource is that yuo have configure a spring bean for manage the properties. 考虑到你的问题的细节,你的问题并不是很清楚,但是@propertySource的典型问题是yuo已经配置了一个用于管理属性的spring bean。 In old years in which xml was the best way for configure Spring you used a namespace configuration that configure a spring bean for use proeprties in your bean, mainly with @Value. 在xml是配置Spring的最佳方式的旧年中,您使用了一个命名空间配置,该命名空间配置将bean配置为在bean中使用proeprties,主要使用@Value。 In java config for benefit of same behaviour you have configure a bean like belove: 在java配置中,为了获得相同的行为,您可以配置像belove这样的bean:

@Bean
public static PlaceholderConfigurerSupport propertyPlaceholderConfigurer() {
       return new PropertySourcesPlaceholderConfigurer();
   }

I hope that this can help you 我希望这可以帮到你

To avoid this kind of problem the issue is to set the jboss.server.config.dir in VM arguments like that : 要避免这种问题,问题是在VM参数中设置jboss.server.config.dir ,如下所示:

-Djboss.server.config.dir="[jboss_repository]/server/[default-all-standard-standalone]/conf" –server

and u set PropertySource like this : 你设置PropertySource是这样的:

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

Or you set ur property like that 或者你设置这样的ur属性

@PropertySource(value = "classpath:application.properties")

When executed, properties will be imported from the application.properties 执行时,将从application.properties导入属性
file, located in the classpath root. 文件,位于类路径根目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM