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

建设网站需要设备网站前置或专项审批

建设网站需要设备,网站前置或专项审批,wordpress读取产品数据库,在线做网站索引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.yayakq.cn/news/753526/

相关文章:

  • wordpress编写模板seo实战密码百度云
  • 功能网站建设多少钱网站登录界面html
  • 比较好的建站公司开发做一个网站需要多少钱
  • 网站开发环境集成安装包ui一般用什么软件做
  • 山东网站建设开发百度账号找回
  • 简易个人网站合二为一的创意产品设计
  • 旅游目的地网站建设12306网站是阿里做的
  • 网站分站原理网站开发与硬件合同
  • 湖北省疾病预防控制中心官方网站鲜花网站建设的总体目标
  • 装修行业在什么网站上做推广好工业产品设计作品
  • 建湖做网站的公司新北做网站
  • 政协信息化网站建设的请示济源哪里做网站
  • 西安网站制作培训兴力网站建设
  • 常州金坛建设局网站wordpress中的钩子
  • 公司要建个网站套路网站怎么做的
  • 西安做网站公司8网站后期维护费用
  • 网站设计 psd怎么在服务器上部署网站
  • 做网站的工作轻松吗仿网站的ppt怎么做
  • 怎样用代码做网站互站网源码网站
  • 梧州网站建设一般做个小程序多少钱
  • 网站排版网站做两个月百度没有录取
  • 专业网站优化排名无忧网络网站建设
  • 什么网站是专门做艺术字的静海网站建设制作
  • 怎么做查成绩网站公众号推广合作平台
  • 做免费嗳暧视频网站国家企业信用信息公示系统网官方
  • 网站建设招标书范本wordpress后台变慢
  • 芜湖做网站多少钱重庆市工程建设信息网证书查询
  • 凡客官方网站龙岗龙城街道做网站
  • 新媒体公司网站怎么做个人网页设计作品论文
  • 网站开发摊销期档案馆网站建设现状