zoukankan      html  css  js  c++  java
  • 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

    声明:本博客文章为原创,只代表本人在工作学习中某一时间内总结的观点或结论。转载时请在文章页面明显位置给出原文链接。

  • 相关阅读:
    jsp四个域对象
    java,qq邮箱发邮件工具类(需要部分修改)
    Java使用qq邮箱发邮件实现
    JavaScript 高级
    JavaScript基础
    JQuery 高级
    JQuery 基础
    团队最后一次作业:总结
    C++多态
    结对编程
  • 原文地址:https://www.cnblogs.com/se7end/p/9598583.html
Copyright © 2011-2022 走看看