Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Spring Environment setup

mariuszs edited this page Nov 5, 2014 · 2 revisions

Description

EnvironmentSetupVerifier is a Spring's ApplicationListener that verifies that you have provided a spring profile upon application execution (via spring.profiles.active system property). If it's not provided the application will close with error.

Example of usage

Example setup for Groovy (note that you don't have to register EnvironmentSetupVerifier as a bean):

@TypeChecked
@Configuration
@EnableAutoConfiguration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan(basePackages = ["com.ofg.microservice", "com.ofg.twitter", "com.mangofactory.swagger"])
@EnableCaching
@EnableAsync
class Application {

    static void main(String[] args) {
        SpringApplication application = new SpringApplication(Application)
        application.addListeners(new EnvironmentSetupVerifier(Profiles.all()))
        application.run(args)
    }
}

where Profiles looks like this:

@TypeChecked
class Profiles {
    public static final String PRODUCTION = "prod"
    public static final String TEST = "test"
    public static final String DEVELOPMENT = "dev"

    static List<String> all() {
        return [PRODUCTION, TEST, DEVELOPMENT]
    }
}

Module configuration

If you want to use only this module just add a dependency:

repositories {
    jcenter()
}

dependencies {
    compile 'com.ofg:micro-infra-spring-base:0.4.1'
}