SpringBoot中获取spring.profiles.active
SpringBoot中获取spring.profiles.active
@Configuration public class ApplicationContextUtils implements ApplicationContextAware { private static Logger logger = LoggerFactory.getLogger(ApplicationContextUtils.class); public static String ACTIVE_PROFILES = null; private static ApplicationContext applicationContext = null; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if(null == ApplicationContextUtils.applicationContext) { ApplicationContextUtils.applicationContext = applicationContext; } } public static ApplicationContext getApplicationContext() { return applicationContext; } public static Object getBean(String name) { return applicationContext.getBean(name); } public static <T> T getBean(Class<T> clazz) { return applicationContext.getBean(clazz); } public static String getActiveProfile() { return applicationContext.getEnvironment().getActiveProfiles()[0]; } }
作者:Se7end
声明:本博客文章为原创,只代表本人在工作学习中某一时间内总结的观点或结论。转载时请在文章页面明显位置给出原文链接。