簡體   English   中英

Spring PropertySource找不到的屬性

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM