无论我如何命令它们,Spring引导始终选择我的application.yml文件中的最后一个配置文件。请帮忙。如果我掏出更多的头发,我什么也没有留下。弹簧启动 - 始终使用的最后一个配置文件
- 使用弹簧引导启动父1.5.1.RELEASE
- 的Maven 3.2.5
- 只有一个在我的神器application.yml。
- 我在日志中看到这一点:osboot.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端点验证了活动配置文件? –