無論我如何命令它們,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端點驗證了活動配置文件? –