[英]Properties not found with Spring PropertySource
配置
@Configuration
@PropertySources({
@PropertySource("classpath*:properties/test-database.properties")
})
public class DataSourceConfiguration {//...
}
支柱位置
D:\Projects\opti\dao\src\main\resources\properties\test-database.properties
D:\\ Projects \\ opti \\ dao \\ src \\ main \\ resources标记为资源文件夹。
考虑到你的问题的细节,你的问题并不是很清楚,但是@propertySource的典型问题是yuo已经配置了一个用于管理属性的spring bean。 在xml是配置Spring的最佳方式的旧年中,您使用了一个命名空间配置,该命名空间配置将bean配置为在bean中使用proeprties,主要使用@Value。 在java配置中,为了获得相同的行为,您可以配置像belove这样的bean:
@Bean
public static PlaceholderConfigurerSupport propertyPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
我希望这可以帮到你
like that : 要避免这种问题,问题是在设置jboss.server.config.dir ,如下所示:
-Djboss.server.config.dir="[jboss_repository]/server/[default-all-standard-standalone]/conf" –server
你设置PropertySource是这样的:
@Configuration
@PropertySource("file:${jboss.server.config.dir}/file.properties")
或者你设置这样的ur属性
@PropertySource(value = "classpath:application.properties")
执行时,将从application.properties导入属性
文件,位于类路径根目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.