| 知乎专栏 |
在 Java 代码中激活 profile
直接指定环境变量来激活 profile:
System.setProperty("spring.profiles.active", "test");
在 Spring 容器中激活 profile:
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.getEnvironment().setActiveProfiles("development");
ctx.register(SomeConfig.class, StandaloneDataConfig.class, JndiDataConfig.class);
ctx.refresh();