我们知道,如果我们在一个不加@Configration 或者 @Service的类中,直接使用
@Autowired注入,比如:
@Autowired private XXXService xxxService;
这样子调试的时候,实际上收到的xxxService对象是null,同时,如果我们使用了
@Value 比如
@Value("${data-collector.basepath}")
这种方式获取yml中 配置信息的时候也是获取不到的,获取出来是个null怎么弄?
-------------------->>>>>>>>开始解决>>>>>>>--------------
1.首先我们需要一个springUtil工具类,用来从spring容器中获取我们想要的Bean
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springfr