【发布时间】:2017-10-26 14:38:46
【问题描述】:
Spring boot 始终选择我的 application.yml 文件中的最后一个配置文件,无论我如何订购它们。请帮忙。如果我再把头发扯掉,我就没有了。
- 使用 spring-boot-starter-parent 1.5.1.RELEASE
- Maven 3.2.5
- 我的工件中只有一个 application.yml。
- 我在日志中看到:o.s.boot.SpringApplication.logStartupProfileInfo 641 - 以下配置文件处于活动状态:DEV
这是我的 application.yml:
server:
context-path: /MyApplicationUI
port: 8480
---
# LOCAL
spring:
profiles: LOCAL
datasource:
driver-class-name: net.sourceforge.jtds.jdbc.Driver
dialect: org.hibernate.dialect.SQLServerDialect
username: #insert username#
encrypted-password: #insert password#
url: jdbc:jtds:sqlserver:blah blah stuff here;
jpa:
database-platform: org.hibernate.dialect.SQLServerDialect
show-sql: true
---
# DEVELOPMENT
spring:
profiles: DEV
datasource:
driver-class-name: net.sourceforge.jtds.jdbc.Driver
dialect: org.hibernate.dialect.SQLServerDialect
username: #insert username#
encrypted-password: #insert password#
url: jdbc:jtds:sqlserver:blah blah stuff here;
jpa:
database-platform: org.hibernate.dialect.SQLServerDialect
show-sql: true
---
# TEST
spring:
profiles: TEST
datasource:
driver-class-name: net.sourceforge.jtds.jdbc.Driver
dialect: org.hibernate.dialect.SQLServerDialect
username: #insert username#
encrypted-password: #insert password#
url: jdbc:jtds:sqlserver:blah blah stuff here;
jpa:
database-platform: org.hibernate.dialect.SQLServerDialect
show-sql: true
我正在通过我自己的 DatasourceConfig.java 加载加密密码:
public class DatasourceConfig {
@Value("${encrypted-password}")
private String encryptedPassword;
/**
* Sets up the datasource with Spring - decrypting password first
*
* @return Datasource
*/
@Bean(name = "dataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource setupDataSource() {
return DataSourceBuilder.create().password(getSecurePassword()).build();
}
/**
* Decrypts encryptedPassword property
*
* @return decryptedPassword
*/
private String getSecurePassword() {
System.out.println("Encrypted password = " + encryptedPassword);
return new AESEncryptionUtils().decryptString(encryptedPassword);
}
...
我没有多个模块:spring boot always using the same profile
万分感谢——感谢任何能提供见解的人。
【问题讨论】:
-
看起来很奇怪,如果您有执行器依赖项,您是否通过 /env 端点验证了活动配置文件?
标签: java spring maven spring-boot