当前springboot 为按顺序执行3个不同的类
1.开始执行
package com.soft.startup;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
* @ClassName AfterServiceStarted
* @Description 项目启动过程中执行一次 顺序为5
* @Author issuser
* @Date 2019/9/11 8:29
* @Version 1.0.0
*/
@Order(5)
@Component
public class AfterServiceStarted implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
}
}
2. 然后执行
package com.soft.startup;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.Properties;
import static io.github.biezhi.ome.OhMyEmail.SMTP_QQ;
/**
* @ClassName AfterEmailService
* @Description 项目启动过程中执行一次 启动顺序为6
* @Author issuser
* @Date 2019/9/11 8:30
* @Version 1.0.0
*/
@Order(6)
@Component
public class AfterEmailService implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("AfterEmailService ...");
}
}
3.最后执行
package com.soft.startup;
import io.github.biezhi.ome.OhMyEmail;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import static io.github.biezhi.ome.OhMyEmail.SMTP_QQ;
/**
* @ClassName AfterEmailService
* @Description 项目启动过程中执行一次 启动顺序为7
* @Author issuser
* @Date 2019/9/11 8:30
* @Version 1.0.0
*/
@Order(7)
@Component
public class AfterOtherService implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
}
}