[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

posted @ 2020-12-04 16:01  Zhentiw  阅读(82)  评论(0编辑  收藏  举报