baoshiwei
2025-04-19 9d960ed0058f9087f49e9741a9af06c3f9116eb0
zhitan-common/src/main/java/com/zhitan/common/utils/spring/SpringUtils.java
@@ -1,12 +1,15 @@
package com.zhitan.common.utils.spring;
import cn.hutool.extra.spring.SpringUtil;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import com.zhitan.common.utils.StringUtils;
@@ -16,7 +19,7 @@
 * @author zhitan
 */
@Component
public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware
public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware
{
    /** Spring应用上下文环境 */
    private static ConfigurableListableBeanFactory beanFactory;
@@ -47,6 +50,11 @@
    public static <T> T getBean(String name) throws BeansException
    {
        return (T) beanFactory.getBean(name);
    }
    public static String getProperty(String key)
    {
        return applicationContext == null ? null : applicationContext.getEnvironment().getProperty(key);
    }
    /**
@@ -155,4 +163,6 @@
    {
        return applicationContext.getEnvironment().getRequiredProperty(key);
    }
}