springboot-启动加载类

项目在启动的时候做一些初始化工作,需要实现ApplicationRunner接口,并重写run()方法,当项目启动时,run()方法便会自动执行。

 

package com.wps.education.runner;
import com.wps.education.Service.IAuthorityService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
@Component//被spring容器管理
@Order(1)//如果多个自定义ApplicationRunner,用来标明执行顺序
public class MyApplicationRunner implements ApplicationRunner {
    @Resource
    private IAuthorityService iAuthorityService;

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        iAuthorityService.loadAuthority();
    }
}

你可能感兴趣的:(java_springboot)