Spring 服务启动 自动执行(ApplicationListener)
2017-08-25 10:30
369 查看
[java] view
plain copy
print?
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
/**
*
* @author yuki_ho
*
*/
@Service
public class StartAddDataListener implements ApplicationListener<ContextRefreshedEvent>
{
@Override
public void onApplicationEvent(ContextRefreshedEvent event)
{
if(event.getApplicationContext().getParent() == null)//root application context 没有parent,他就是老大.
{
//需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。
}
}
}
plain copy
print?
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
/**
*
* @author yuki_ho
*
*/
@Service
public class StartAddDataListener implements ApplicationListener<ContextRefreshedEvent>
{
@Override
public void onApplicationEvent(ContextRefreshedEvent event)
{
if(event.getApplicationContext().getParent() == null)//root application context 没有parent,他就是老大.
{
//需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。
}
}
}
相关文章推荐
- web服务启动spring自动执行ApplicationListener的用法
- Spring 服务启动 自动执行(ApplicationListener)
- web服务启动spring自动执行ApplicationListener的用法
- Web服务启动时自动加载Servlet,并执行service处理
- 为什么spring cloud服务启动之后回到命令行会自动挂掉
- Spring容器启动后注入service到Servlet并自动执行
- springBoot 设置服务启动时执行代码
- spring web.xml配置服务启动后执行文件
- Web服务启动时自动加载Servlet,并执行service处理 监听处理
- web 服务启动时自动执行某类的代码
- 如何把spring微服务部署为Windows Service并开机自动启动
- IIS启动,就自动执行一个WCF服务方法的解决方案实现的疑问?
- spring启动自动后执行特定方法
- Spring容器启动后自动执行Servlet进行预处理
- spring项目启动完成后,自动执行一次某个特定方法。
- Spring容器启动后自动执行Servlet进行预处理
- 【任务笔记】创建windows操作系统下的服务进程,并随操作系统启动自动开始执行
- Spring容器启动后自动执行Servlet进行预处理
- web 服务启动时自动执行某类的代码
- 使用job自动抓取网页数据发送邮件,以springboot服务启动