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

东莞网站seo推广优化做网站都是怎么收费

东莞网站seo推广优化,做网站都是怎么收费,网站备案信息不准确,网贷网站开发Spring Boot为开发者提供了多种方式在应用启动时执行自定义代码#xff0c;这些方式包括注解、接口实现和事件监听器。在本篇博客中#xff0c;我们将探讨一些常见的方法#xff0c;以及如何利用它们在应用启动时执行初始化逻辑。 1. PostConstruct注解 PostConstruct注解…Spring Boot为开发者提供了多种方式在应用启动时执行自定义代码这些方式包括注解、接口实现和事件监听器。在本篇博客中我们将探讨一些常见的方法以及如何利用它们在应用启动时执行初始化逻辑。 1.  PostConstruct注解 PostConstruct注解可以标注在方法上该方法将在类被初始化后调用。在Spring Boot应用中你可以使用这个注解来执行一些初始化的逻辑。 PostConstruct public void doSomething(){// 在应用启动后执行的代码System.out.println(do something); } 2.  ApplicationListener接口 实现ApplicationListener接口并监听ApplicationStartedEvent事件这样你的逻辑将在应用启动后被触发。 import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener;public class MyApplicationListener implements ApplicationListenerApplicationStartedEvent {Overridepublic void onApplicationEvent(ApplicationStartedEvent event) {// 在应用启动后执行的代码System.out.println(ApplicationListener executed);} } 3.  EventListener注解 使用EventListener注解可以将方法标记为事件监听器并在特定事件发生时执行。 import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.event.EventListener;public class MyEventListener {EventListener(ApplicationStartedEvent.class)public void onApplicationEvent() {// 在应用启动后执行的代码System.out.println(EventListener executed);} } 4.  ApplicationRunner接口 实现ApplicationRunner接口该接口的run方法会在Spring Boot应用启动后执行。 import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner;public class MyApplicationRunner implements ApplicationRunner {Overridepublic void run(ApplicationArguments args) throws Exception {// 在应用启动后执行的代码System.out.println(ApplicationRunner executed);} } 5.  CommandLineRunner接口 与ApplicationRunner类似CommandLineRunner接口的run方法也在应用启动后执行。 public class MyCommandLineRunner implements CommandLineRunner {Overridepublic void run(String... args) throws Exception {// 在应用启动后执行的代码System.out.println(CommandLineRunner executed);} } Demo代码 完整如下 import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.EventListener;import javax.annotation.PostConstruct;SpringBootApplication public class Application implementsApplicationListenerApplicationStartedEvent,CommandLineRunner,ApplicationRunner {/*** 本次执行先后顺序为没有设置order* PostConstruct、ApplicationListener、EventListener注解、ApplicationRunner、CommandLineRunner* param args*/public static void main(String[] args) {SpringApplication.run(Application.class, args);}PostConstructpublic void doSomething(){// 在应用启动后执行的代码System.out.println(do something 11111111111);System.out.println(PostConstruct注解启动);System.out.println();}EventListener(ApplicationStartedEvent.class)public void onApplicationEvent() {// 在应用启动后执行的代码System.out.println(do something 22222222222);System.out.println(EventListener 注解启动 executed);System.out.println();}Overridepublic void onApplicationEvent(ApplicationStartedEvent event) {// 在应用启动后执行的代码System.out.println(do something 3333333333);System.out.println(ApplicationListener executed);System.out.println();}Overridepublic void run(String... args) throws Exception {// 在应用启动后执行的代码System.out.println(do something 44444444);System.out.println(CommandLineRunner启动);System.out.println();}Overridepublic void run(ApplicationArguments args) throws Exception {// 在应用启动后执行的代码System.out.println(do something 55555555);System.out.println(ApplicationRunner启动);System.out.println();} }Demo分析 PostConstruct注解方法 (doSomething方法) 在类初始化后被调用因此会首先输出。 ApplicationListener接口方法 (onApplicationEvent方法) 在应用启动后执行会输出其相关的信息。 EventListener注解方法 (onApplicationEvent方法) 同样在应用启动后执行会输出其相关的信息。 ApplicationRunner接口方法 (run方法) 在ApplicationListener之后执行它用于在Spring Boot应用启动后执行一些额外的逻辑。 CommandLineRunner接口方法 (run方法) 也在ApplicationListener之后执行用于在Spring Boot应用启动后执行一些额外的逻辑。 总结 通过以上几种方式你可以根据项目的需求选择合适的初始化方法。无论是使用注解、接口实现还是事件监听器Spring Boot提供了灵活的机制来管理应用启动时的自定义逻辑使得开发者能够更方便地控制应用的初始化过程。在实际项目中通常根据具体场景选择其中一种或多种方式以满足不同的需求。
http://www.pierceye.com/news/289334/

相关文章:

  • 湖南住房和建设厅网站免费的网站建设开发
  • 苏州园区建设网站首页娱乐新闻做的好的网站
  • 江苏省建设集团有限公司网站做网站的软件dw下载
  • 做网站需要学些什么软件杭州学校网站建设
  • 建设银行网上银行网站可以开通网银wordpress 种子插件
  • 一般网站图标是用什么做的网件路由器无线中继
  • 手机 网站 开发淘宝店铺网站策划书
  • 网站建设规划方案书滨州网站建设 中企动力
  • 网站建设品牌推荐做网站必须要公网ip
  • 做网站卖东西赚钱wordpress微信网站
  • 商丘网站建设有限公司店面设计费用
  • 张店学校网站建设公司合肥有哪些seo网络公司
  • 做博客网站的空间容量需要多少北京简盟产品设计有限公司
  • 哪些网站怎么进定制开发平台
  • 【郑州网站建设】wordpress自定义后台单页模板
  • 铭誉摄影网站北京网站建设开发
  • 单位还能建设网站吗做网站的程序员留备份
  • 松江团购做网站产品开发的基本流程
  • 织梦后台网站栏目空白小广告制作
  • 钦州建设局网站云南网站建设招商
  • 韩国风格网站php源码网站怎么放到服务器上
  • 网站调优yandex搜索引擎入口
  • 医院网站建设具体内容商丘网站制作电话
  • 别人做的网站直播网站
  • 足球梦网站建设的基本思路沧州做企业网站
  • 招标建设网站什么是微信wordpress
  • 建设银行网站连不上成都网站快照优化公司
  • 网站 永久关停 请示广州网站建设骏域网站
  • 个人建站模板外国网站翻墙怎么做
  • 保定网站设计制作公司有经验的中山网站建设