Spring boot啓動之後執行方法 CommandLineRunner

效果圖:圖片

在tomcat重啓的時候調用了一個刪除方法,主要是實現CommandLineRunner接口,這個接口比較好的就是可以使用@Order(value=1)這個註解,可以根據value的值來進行執行先後權限設置,1是最高權限,最先執行,不多說上乾貨~

Class:

package com.htsc.bcr.web;

import com.htsc.bcr.service.AsyncJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: xj
 * @Date: 2017/5/27 12:43
 */
@Component
public class InstallerClass implements CommandLineRunner {
    @Autowired
    private AsyncJobService asyncJobService;

    @Override
    @Transactional
    public void run(String... strings) throws Exception {
        asyncJobService.deleteAsyncJobByStart();
    }
}



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