Profile annotation for springboot uses

  spring, springboot

@Profile

This annotation can be used in conjunction with @Configuration to specify the configuration of different profile using java code. It can be annotated on classes or methods of @ beans.

Comments on Class

dev

@Configuration
@Profile("dev")
public class CacheConfigDev {

    private static final Logger log = LoggerFactory.getLogger(CacheConfigDev.class);

    @Bean
        public CacheManager concurrentMapCacheManager() {
        log.debug("Cache manager is concurrentMapCacheManager");
                return new ConcurrentMapCacheManager("movieFindCache");
        }

}

prod

@Configuration
@Profile("prod")
public class CacheConfigProd {

    private static final Logger log = LoggerFactory.getLogger(CacheConfigProd.class);

    @Bean
    public CacheManager cacheManager() {
        log.debug("Cache manager is ehCacheCacheManager");
        return new EhCacheCacheManager(ehCacheCacheManager().getObject());
    }

    @Bean
    public EhCacheManagerFactoryBean ehCacheCacheManager() {
        EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
        cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
        cmfb.setShared(true);
        return cmfb;
    }

}

Comments on @Bean

@Configuration
public class ProfileConfig {

    @Bean(name="dev")
    @Profile("dev")
     DevProfile devProfile() {
        return new DevProfile();
    }

    @Bean(name="prod")
    @Profile("prod")
     ProdProfile ProdProfile() {
        return new ProdProfile();
    }
}

docs