依赖JAR中属性文件的键的替代值

时间:2019-03-24 17:31:32

标签: java spring

我的应用程序具有一个依赖关系,该依赖关系包含具有键app_port = $ {app_port:8080}的默认属性文件,并且该属性文件源自JAR,现在我想用8081覆盖此键的值,并创建了另一个属性文件并放入app_port = $ {app_port:8081},但是当我尝试使用env.getProperty(“ app_port”)或@Value(“ $ {app_port}”)来访问它时,它并没有覆盖值

我尝试在网上搜索,但发现是用于引导的:https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config 如果我使用VM参数-Dapp_port = 8081传递值,则该值有效

库代码:

@PropertySources({
@PropertySource("classpath:config/config.properties")
})
public class MessagingConfig

我的应用代码:

@PropertySources({
@PropertySource("classpath:config/app_config.properties")
})
public class AppConfig

config / app_config.properties的内容

app_port=${app_port:8081}

我需要一种将app_port的值覆盖为8081的方法

1 个答案:

答案 0 :(得分:0)

app_port=${app_port:8081}基本上告诉Spring使用app_port的当前值,默认值为8081。

如果您在app_port=8081内使用app_config.properties,则应该可以。

相关问题