Spring Boot配置文件特定属性

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

我正在使用Spring Boot,并希望拥有多个配置文件特定的属性文件。文档说明:

除了application.properties文件之外,还可以使用命名约定application- {profile} .properties定义配置文件特定属性。

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-profile-specific-properties

但是我有多个属性文件(例如db.properties)。我正在加载当前加载此非配置文件的特定文件:

@Configuration
@PropertySource( {"classpath:db.properties"} )
class DataSourceConfig  {
    @Value("db.server") String server;
...
}

如何将这两个东西组合在一起,所以它加载db-dev.properties就像Spring Boot为application.properties做的那样

这听起来应该很容易,但我无法解决如何做到这一点?!

spring-boot
2个回答
1
投票

Java -jar my-spring-boot.jar --spring.profiles.active = test你可以通过命令行设置profile.active =你的环境


0
投票

我刚刚看到你使用@PropertySourcedocs说:

application.properties(或application.yml)的配置文件特定变体和通过@ConfigurationProperties引用的文件被视为已加载文件。

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