您的位置:首页 > 移动开发

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容器初始化完成后就会执行该方法。   

      

        }   

         

  

         

    }  

  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: