您的位置:首页 > 编程语言 > Java开发

springboot项目启动执行特定方法

2019-01-23 14:32 666 查看

参考博客:
https://www.geek-share.com/detail/2715447781.html
实现ApplicationRunner接口即可
直接上代码:

/**
* @author : lichenfei
* @date : 2019年1月23日
* @time : 下午2:12:20
*
*/
package com.lcf.app.start;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
* @author : lichenfei
* @date : 2019年1月23日
* @time : 下午2:12:20
*
*/
@Component // bean组件注解
@Order(1) // 指定执行顺序
public class StartOne implements ApplicationRunner {

/*
* 项目启动时执行的方法
*/
public void run(ApplicationArguments args) throws Exception {
System.err.println("StartOne方法开始执行...");
}

}
/**
* @author : lichenfei
* @date : 2019年1月23日
* @time : 下午2:12:20
*
*/
package com.lcf.app.start;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
* @author : lichenfei
* @date : 2019年1月23日
* @time : 下午2:12:20
*
*/
@Component // bean组件注解
@Order(2) // 指定执行顺序
public class StartTwo implements ApplicationRunner {

/*
* 项目启动时执行的方法
*/
public void run(ApplicationArguments args) throws Exception {
System.err.println("StartTwo方法开始执行...");

}

}

运行结果:

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