**
在监听(Listener)类如何调用Service中的方法
**
前言
很多时候在项目启动后我们需要监听某些状态来实现不同的操作,在监听类中调用Service层的业务逻辑,直接注入Spring管理的Bean显然是行不通的,可以手动加载该Bean!
话不多说!直接上代码:
这是一个工具类:
package com.shallowdrink.springBoot;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
//关键就是实现ApplicationContextAware 这个接口
public class SpringJobBeanFactory implements ApplicationContextAware {
private static ApplicationContext applicationContext;