簡體   English   中英

Spring @PropertySource 值不會被覆蓋

[英]Spring @PropertySource value not overridding

在我的 sprint 啟動應用程序中,我有一個配置類來讀取屬性文件: common.propertiesdev.properties 我在兩個屬性文件中都有相同的密鑰server.url 該值不會被覆蓋。 根據 spring 文檔,應采用最后一個屬性文件值。 但它不起作用。 我正在使用 spring 注釋@PropertySource來讀取值。

服務器配置類

@Component
@PropertySources(
{
    @PropertySource(value = "file:Common/config/common.properties", ignoreResourceNotFound = true),
    @PropertySource(value = "file:Dev/config/dev.properties", ignoreResourceNotFound = true)
})
public final class ServerConfiguration {


private final ApplicationContext applicationContext;

/**
 * The Server URL
 */
@Value("${server.url}")
private String serverUrl;

}

公共屬性

server.url=ws://some ip

開發屬性

server.url=ws://localhost:8080

始終采用common.properties的值。 我嘗試更改順序,但仍然無法正常工作。

您需要在 application.properties 文件中添加您的活動配置文件

spring.profiles.active=dev

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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