Spring PropertySource找不到的属性

问题描述 投票:3回答:2

配置

@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标记为资源文件夹。

java spring properties annotations filenotfoundexception
2个回答
1
投票

考虑到你的问题的细节,你的问题并不是很清楚,但是@propertySource的典型问题是yuo已经配置了一个用于管理属性的spring bean。在xml是配置Spring的最佳方式的旧年中,您使用了一个命名空间配置,该命名空间配置将bean配置为在bean中使用proeprties,主要使用@Value。在java配置中,为了获得相同的行为,您可以配置像belove这样的bean:

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

我希望这可以帮到你


1
投票

要避免这种问题,问题是在VM参数中设置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")

或者你设置你的属性

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

执行时,将从application.properties导入属性 文件,位于类路径根目录中。

© www.soinside.com 2019 - 2024. All rights reserved.