为什么做电影网站没有流量,做网站入门,网站诊断示例,宁波网络公司选哪家需求#xff1a;应用程序启动后#xff0c;初始化基础数据、加密证书等操作。 可以使用CommandLineRunner接口来实现#xff0c;在SpringBoot.run()之后完成资源的初始化工作。 注意#xff1a;多个Runner需要顺序启动的话#xff0c;可以使用Order注解 package sun.flowe… 需求应用程序启动后初始化基础数据、加密证书等操作。 可以使用CommandLineRunner接口来实现在SpringBoot.run()之后完成资源的初始化工作。 注意多个Runner需要顺序启动的话可以使用Order注解 package sun.flower.diver.modules.system.init;import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;/*** 应用程序启动后加载基础数据 Runner** Author YangXuyue* Date 2018/10/28 13:48*/
Component
Order(1) public class BaseDataRunner implements CommandLineRunner { Override public void run(String... strings) throws Exception { System.out.println(start init base data); } } package sun.flower.diver.modules.system.init;import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;/*** 应用程序启动后加载证书 Runner** Author YangXuyue* Date 2018/10/28 13:50*/
Component
Order(2) public class CertificateRunner implements CommandLineRunner { Override public void run(String... strings) throws Exception { System.out.println(start init certificate info); } } package sun.flower.diver;import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;SpringBootApplication
// 添加注解 EnableDiscoveryClient只有这样服务注册、心跳检测相关配置信息才能被自动加载
EnableDiscoveryClient public class DiverApplication { public static void main(String[] args) { System.out.println(application start); SpringApplication application new SpringApplication(DiverApplication.class); // 添加监听器此时监听器类不需要标注是一个Bean //application.addListeners(new BaseListener()); application.setBannerMode(Banner.Mode.OFF); application.run(args); System.out.println(application started); } } 转载于:https://www.cnblogs.com/yang21/p/9865399.html