| | |
| | | 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; |
| | | |
| | |
| | | * @author zhitan |
| | | */ |
| | | @Component |
| | | public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware |
| | | public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware |
| | | { |
| | | /** Spring应用上下文环境 */ |
| | | private static ConfigurableListableBeanFactory beanFactory; |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return applicationContext.getEnvironment().getRequiredProperty(key); |
| | | } |
| | | |
| | | |
| | | } |