java-profile使用

版权声明:本文为pureszgd原创文章,未经允许不得转载, 要转载请评论留言! https://blog.csdn.net/pureszgd/article/details/84023477
@Configuration
public class ProfileConfig {
    @Bean
    @Profile("dev")
    public DemoBean devDemoBean() {
        return new DemoBean("from development profile");
    }

    @Bean
    @Profile("prod")
    public DemoBean prodDemoBean() {
        return new DemoBean("from production profile");
    }
}


public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

    context.getEnvironment().setActiveProfiles("prod");
    context.register(ProfileConfig.class);
    context.refresh();

    DemoBean demoBean = context.getBean(DemoBean.class);

    System.out.println(demoBean.getContent());

    context.close();
}

猜你喜欢

转载自blog.csdn.net/pureszgd/article/details/84023477