update ruoyi-common/src/main/java/com/ruoyi/common/utils/spring/SpringUtils.java.

dep_wangsr
Hacker 4 years ago committed by Limy
parent e9b8835521
commit 8ca210d214

@ -1,5 +1,6 @@
package com.ruoyi.common.utils.spring; package com.ruoyi.common.utils.spring;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.aop.framework.AopContext; import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@ -13,17 +14,25 @@ import org.springframework.stereotype.Component;
* @author ruoyi * @author ruoyi
*/ */
@Component @Component
public final class SpringUtils implements BeanFactoryPostProcessor public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware
{ {
/** Spring应用上下文环境 */ /** Spring应用上下文环境 */
private static ConfigurableListableBeanFactory beanFactory; private static ConfigurableListableBeanFactory beanFactory;
private static ApplicationContext applicationContext;
@Override @Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
{ {
SpringUtils.beanFactory = beanFactory; SpringUtils.beanFactory = beanFactory;
} }
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
SpringUtils.applicationContext = applicationContext;
}
/** /**
* *
* *
@ -111,4 +120,25 @@ public final class SpringUtils implements BeanFactoryPostProcessor
{ {
return (T) AopContext.currentProxy(); return (T) AopContext.currentProxy();
} }
/**
* null
*
* @return
*/
public static String[] getActiveProfiles()
{
return applicationContext.getEnvironment().getActiveProfiles();
}
/**
*
*
* @return
*/
public static String getActiveProfile()
{
final String[] activeProfiles = getActiveProfiles();
return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
}
} }

Loading…
Cancel
Save