spring 裝載完成默認啓動指定方法

package com.sanss.monitor.server.task;

import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class DefaultJob implements ApplicationListener<ContextRefreshedEvent>{

	
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		
		if(event.getApplicationContext().getParent() == null){
			//代碼
		}
		
	}


}


<!--      需要Spring容器加載這個Bean -->
 <bean class="com.sanss.monitor.server.task.DefaultJob"/>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章