我正在使用Spring Boot,并希望拥有多个配置文件特定的属性文件。文档说明:
除了application.properties文件之外,还可以使用命名约定application- {profile} .properties定义配置文件特定属性。
但是我有多个属性文件(例如db.properties
)。我正在加载当前加载此非配置文件的特定文件:
@Configuration
@PropertySource( {"classpath:db.properties"} )
class DataSourceConfig {
@Value("db.server") String server;
...
}
如何将这两个东西组合在一起,所以它加载db-dev.properties
就像Spring Boot为application.properties
做的那样
这听起来应该很容易,但我无法解决如何做到这一点?!
Java -jar my-spring-boot.jar --spring.profiles.active = test你可以通过命令行设置profile.active =你的环境
我刚刚看到你使用@PropertySource
。 docs说:
application.properties(或application.yml)的配置文件特定变体和通过@ConfigurationProperties引用的文件被视为已加载文件。