[Java Spring] @Profile

For example, inside code, we want production env & dev env print different time format.

    @Bean
    @Profile("!dev")
    public TimeService timeService(){
        return new TimeService(true);
    }

    @Bean
    @Profile("dev")
    public TimeService timeService12(){
        return new TimeService(false);
    }

Setup VM Options: 

-Dspring.profiles.active=prod
// or
-Dspring.profiles.active=dev

原文地址:https://www.cnblogs.com/Answer1215/p/14086334.html