软件编程
位置:首页>> 软件编程>> java编程>> Spring Boot启动时调用自己的非web逻辑

Spring Boot启动时调用自己的非web逻辑

作者:zhangjikuan  发布时间:2022-02-15 11:40:10 

标签:spring,boot启动,调用

在spring Boot中,有些代码是WEB功能,例如API等,但是有些逻辑是非WEB,启动时就要调用并持续运行的,该如何加载自己的非WEB逻辑呢?

SpringBootApplication类实现CommandLineRunner并覆盖run()方法


@SpringBootApplication
public class ZjkApplication implements CommandLineRunner{
/**
 * @param args
 */
public static void main(String[] args) {
 // TODO Auto-generated method stub
 // WEB
 SpringApplication.run(ZjkApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
 //your logic
 System.out.println("into zjk run");
}
}

使用上面方式启动的SPRING BOOT,即可以运行WEB又可以运行自己的逻辑

总结

以上所述是小编给大家介绍的Spring Boot启动时调用自己的非web逻辑网站的支持!

来源:http://blog.csdn.net/zhangjikuan/article/details/76181657

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com