Spring boot-profile, die mit externen Eigenschaften

Ich würde gerne setup 3 profile in den Frühling starten: die Produktion,Entwicklung,test mit einer externen config-Datei.

Application-Klasse:

@SpringBootApplication
public class Application {

    public static void main(String[] args){
        SpringApplication.run( Application.class, args );
    }
}

AppConfig-Klasse:

@Configuration
@PropertySources({
        @PropertySource("config/application.yml"),
        @PropertySource(value = "file:${external.config}")
})

@ConfigurationProperties
public class AppConfig {

}

config/application.yml:

---
spring.profiles: production
endpoints.enabled: false
---
spring.profiles: development,test
endpoints.enabled: true
info.version: @project.version@
info.test: Test dev or test
info.profile: ${spring.profiles.active}
---

external.config: ${user.home}/.myapp/application.properties

.myapp/application.Eigenschaften:

spring.profiles.active=production
info.version=5

Die Ausgabe des spring-boot-Antrieb /info

{
  version: "5",
  test: "Test dev or test",
  profile: "production"
}

Erwartete Ausgabe:

404 because of the endpoints.enabled: false

Frühjahr-boot-Antrieb /env

spring.profiles.active: "production"

InformationsquelleAutor Gergely Peidl | 2015-09-12

Schreibe einen Kommentar