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

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

  • 相关阅读:
    注释
    Java三种嵌入jsp的方法
    JSP page指令
    Web应用的目录结构
    Tomcat安装和配置
    动态网页和静态网页的区别
    B/S架构与C/S架构的区别
    URL
    常用SQL查询语句
    SQL--Delete语句
  • 原文地址:https://www.cnblogs.com/se7end/p/9598583.html
Copyright © 2011-2022 走看看