当前位置: 首页 > news >正文

铂爵旅拍婚纱摄影官网石狮seo

铂爵旅拍婚纱摄影官网,石狮seo,上海疫情最新消息今天又封了,三星网上商城如何学生认证CommandLineRunner 和 ApplicationRunner 都是 Spring Boot 中用于在应用启动后执行特定逻辑的接口。它们的主要区别在于传递的参数类型和执行顺序。下面我将为您详细解释它们的用途、使用案例以及执行顺序。 CommandLineRunner CommandLineRunner 是一个接口,它有…

CommandLineRunnerApplicationRunner 都是 Spring Boot 中用于在应用启动后执行特定逻辑的接口。它们的主要区别在于传递的参数类型和执行顺序。下面我将为您详细解释它们的用途、使用案例以及执行顺序。

CommandLineRunner

CommandLineRunner 是一个接口,它有一个方法 run,接受一个类型为 String[] 的参数,表示应用启动时传递的命令行参数。通常用于执行一些与命令行参数相关的初始化操作。

使用案例:

假设您的应用需要根据命令行参数初始化一些配置,您可以使用 CommandLineRunner 来实现:

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}@Component
class MyCommandLineRunner implements CommandLineRunner {@Overridepublic void run(String... args) throws Exception {// 根据命令行参数执行初始化操作if (args.length > 0 && args[0].equals("init")) {System.out.println("执行初始化操作");}}
}

在这个例子中,如果您在启动应用时传递了命令行参数 “init”,MyCommandLineRunnerrun 方法将会执行相应的初始化操作。

ApplicationRunner

ApplicationRunner 是一个接口,也有一个方法 run,接受一个类型为 ApplicationArguments 的参数,主要目的是在应用程序上下文加载之后运行一些代码。

使用案例:

假设您的应用需要在应用程序上下文加载之后运行一些代码,您可以使用 ApplicationRunner

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}@Component
class MyApplicationRunner implements ApplicationRunner {@Overridepublic void run(ApplicationArguments args) throws Exception {// 执行初始化操作}
}

执行顺序的定义:

在 Spring Boot 中,CommandLineRunnerApplicationRunner 的执行顺序是通过 @Order 注解或 Ordered 接口来定义的。通过这些方式,您可以明确指定执行的顺序,或者让 Spring Boot 自动根据数字值进行排序。

以下是一个示例,展示了如何使用 @Order 注解来定义执行顺序:

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}@Component
@Order(2)
class MyCommandLineRunner1 implements CommandLineRunner {@Overridepublic void run(String... args) throws Exception {System.out.println("MyCommandLineRunner1 执行");}
}@Component
@Order(1)
class MyCommandLineRunner2 implements CommandLineRunner {@Overridepublic void run(String... args) throws Exception {System.out.println("MyCommandLineRunner2 执行");}
}

在这个示例中,MyCommandLineRunner2run 方法会在 MyCommandLineRunner1run 方法之前执行,因为它们分别使用了不同的 @Order 值。

总之,CommandLineRunnerApplicationRunner 接口都是用于在 Spring Boot 应用启动后执行特定逻辑的强大工具。您可以根据需要使用它们来执行初始化操作、业务逻辑或其他自定义操作,并通过 @OrderOrdered 接口来控制它们的执行顺序。

http://www.tj-hxxt.cn/news/74023.html

相关文章:

  • 大桥外语官方网站星做宝贝青岛神马排名优化
  • 县政府门户网站建设实施方案google搜索排名优化
  • 自己做的网站提示危险济南谷歌推广
  • 西咸新区新闻广州百度推广优化
  • 网上建立网站百度seo规则
  • 厦门seo网络推广seo主要做什么工作
  • 亚马逊网站运营怎么做东莞seo靠谱
  • 怎么做幼儿园网站介绍ppt重庆排名seo公司
  • 网站内容页怎么做淘宝seo搜索优化工具
  • 智慧团建注册登记入口简述seo的基本步骤
  • 杭州的网站建设公司有哪些百度移动端优化
  • 找公司做网站的好处独立站seo怎么做
  • 做外贸出口衣服的网站网站后端开发
  • 虚拟空间怎么做网站目录指向自己怎么做网站网页
  • ftp wordpress 搬站百度地址
  • 梧州网站建设公司seo推广平台服务
  • 怎么样做钓鱼网站免费建立网站步骤
  • 人妖和美女做视频网站百度助手官网
  • seo网络推广哪家专业网络优化工程师证书
  • 江苏荣邦建设有限公司网站seo网络推广优化教程
  • 可以做任务看漫画的漫画网站优化网站快速排名软件
  • 深圳网站建设公司信息网站如何做关键词优化
  • 什么网站做奢侈品的工厂店提高网站排名软件
  • 路桥网站制作广州新闻最新消息今天
  • o2o商城网站系统开发厦门人才网个人版
  • 手机网站活动策划方案线上营销平台有哪些
  • 南开做网站的公司源云推广
  • 计算机网站的开发流程百度游戏app下载
  • 用ci框架如何做动态网站seo优化网站源码
  • wordpress路由插件开发高级seo是什么职位