代码示例
/**
* 启动监听器
*/
@Component
public class AppListener implements ApplicationListener<ApplicationReadyEvent> {
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
// 获取当前的环境,如果是test,则直接返回
ConfigurableApplicationContext applicationContext = event.getApplicationContext();
ConfigurableEnvironment environment = applicationContext.getEnvironment();
String[] activeProfiles = environment.getActiveProfiles();
for (String activeProfile : activeProfiles) {
if ("test".equals(activeProfile)) {
return;
}
}
}
}
参考