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

网站建设的静态网页作业怎么建自己的网站?

网站建设的静态网页作业,怎么建自己的网站?,做电商需要学哪些基础,抖音seo软件工具SpringBoot系列之启动成功后执行业务逻辑。在Springboot项目中经常会遇到需要在项目启动成功后#xff0c;加一些业务逻辑的#xff0c;比如缓存的预处理#xff0c;配置参数的加载等等场景#xff0c;下面给出一些常有的方法 实验环境 JDK 1.8SpringBoot 2.2.1Maven 3.2…SpringBoot系列之启动成功后执行业务逻辑。在Springboot项目中经常会遇到需要在项目启动成功后加一些业务逻辑的比如缓存的预处理配置参数的加载等等场景下面给出一些常有的方法 实验环境 JDK 1.8SpringBoot 2.2.1Maven 3.2Mysql 8.0.26开发工具 IntelliJ IDEA smartGit 动手实践 ApplicationRunner和CommandLineRunner 比较常有的使用Springboot框架提供的ApplicationRunner和CommandLineRunner这两种Runner可以实现在Springboot项目启动后执行我们自定义的业务逻辑然后执行的顺序可以通过Order进行排序参数值越小越早执行 写个测试类实现ApplicationRunner接口注意加上Component才能被Spring容器扫描到 package com.example.jedis.runner;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;Order(1) Component Slf4j public class TestApplicationRunner implements ApplicationRunner {Overridepublic void run(ApplicationArguments args) throws Exception {log.info(TestApplicationRunner);} } 实现CommandLineRunner接口 package com.example.jedis.runner;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;Order(2) Component Slf4j public class TestCommandLineRunner implements CommandLineRunner {Overridepublic void run(String... args) throws Exception {log.info(TestCommandLineRunner);} } ApplicationListener加ApplicationStartedEvent SpringBoot基于Spring框架的事件监听机制提供ApplicationStartedEvent可以对SpringBoot启动成功后的监听基于事件监听机制我们可以在SpringBoot启动成功后做一些业务操作 package com.example.jedis.listener;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component;Component Slf4j public class TestApplicationListener implements ApplicationListenerApplicationStartedEvent {Overridepublic void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {log.info(onApplicationEvent);} } SpringApplicationRunListener 如果要在启动的其它阶段做业务操作可以实现SpringApplicationRunListener接口例如要实现打印swagger的api接口文档url可以在对应方法进行拓展即可 package com.example.jedis.listener;import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplicationRunListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment;import java.net.InetAddress;Slf4j public class TestSpringApplicationRunListener implements SpringApplicationRunListener {private final SpringApplication application;private final String[] args;public TestSpringApplicationRunListener(SpringApplication application, String[] args) {this.application application;this.args args;}Overridepublic void starting() {log.info(starting...);}Overridepublic void environmentPrepared(ConfigurableEnvironment environment) {log.info(environmentPrepared...);}Overridepublic void contextPrepared(ConfigurableApplicationContext context) {log.info(contextPrepared...);}Overridepublic void contextLoaded(ConfigurableApplicationContext context) {log.info(contextLoaded...);}Overridepublic void started(ConfigurableApplicationContext context) {log.info(started...);}SneakyThrowsOverridepublic void running(ConfigurableApplicationContext context) {log.info(running...);ConfigurableEnvironment environment context.getEnvironment();String port environment.getProperty(server.port);String contextPath environment.getProperty(server.servlet.context-path);String docPath port contextPath /doc.html;String externalAPI InetAddress.getLocalHost().getHostAddress();log.info(\n Swagger API: Local-API: \t\thttp://127.0.0.1:{}\n\t External-API: \thttp://{}:{}\n\t,docPath, externalAPI, docPath);}Overridepublic void failed(ConfigurableApplicationContext context, Throwable exception) {log.info(failed...);} } 在/META-INF/spring.factories配置文件配置 org.springframework.boot.SpringApplicationRunListener\com.example.jedis.listener.TestSpringApplicationRunListener源码分析 在Springboot的run方法里找到如下的源码大概看一下就可以知道里面是封装了对Runner和SpringApplicationRunListener的调用 public ConfigurableApplicationContext run(String... args) {StopWatch stopWatch new StopWatch();stopWatch.start();ConfigurableApplicationContext context null;CollectionSpringBootExceptionReporter exceptionReporters new ArrayList();this.configureHeadlessProperty();SpringApplicationRunListeners listeners this.getRunListeners(args);// SpringApplicationRunListener调用listeners.starting();Collection exceptionReporters;try {ApplicationArguments applicationArguments new DefaultApplicationArguments(args);ConfigurableEnvironment environment this.prepareEnvironment(listeners, applicationArguments);this.configureIgnoreBeanInfo(environment);Banner printedBanner this.printBanner(environment);context this.createApplicationContext();exceptionReporters this.getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[]{ConfigurableApplicationContext.class}, context);this.prepareContext(context, environment, listeners, applicationArguments, printedBanner);this.refreshContext(context);this.afterRefresh(context, applicationArguments);stopWatch.stop();if (this.logStartupInfo) {(new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), stopWatch);}// SpringApplicationRunListener startlisteners.started(context);// 调用所有的Runnerthis.callRunners(context, applicationArguments);} catch (Throwable var10) {this.handleRunFailure(context, var10, exceptionReporters, listeners);throw new IllegalStateException(var10);}try {// SpringApplicationRunListener running执行listeners.running(context);return context;} catch (Throwable var9) {this.handleRunFailure(context, var9, exceptionReporters, (SpringApplicationRunListeners)null);throw new IllegalStateException(var9);}}
http://www.sadfv.cn/news/169112/

相关文章:

  • 门户网站建设如何入账网站策划的最终体现是什么
  • 网站建设单位是什么爱站权重是怎么计算的
  • 网站备案去哪二级域名网站优化
  • 做的最好的门户网站装修设计费多少钱一平方
  • 我自己做网站石家庄网站备案
  • 山东大良网站建设免费做企业推广的网站
  • 南阳网站建站公司长阳网站建设
  • 宁波网站建设免费咨询wordpress两栏主题
  • 建立网站 英语怎么说新手学做网站 pdf 下载
  • 软件下载网站整站源码许昌网站制作
  • 安徽鲲鹏建设集团有限公司网站重庆好的网站建设
  • 公司网站工商备案怎么做电子商务网站架构
  • 不会编程 做网站全球电商平台排行榜前十名
  • 网站背景图片优化制作h5网页软件
  • 汽车门户网站开发网站的当前位置导航如何做
  • 免费网络推广网站大全网站备案幕布怎么做
  • 西安做网站建设的广东粤建设计院网站
  • 百度站长平台网页版网站seo收录工具
  • 亚当学院网站视频建设教程成都网站建设q479185700棒
  • 万网制作淘宝客网站做企业网站有哪些系统
  • 营销网站建设哪里好薇湖南门户网站建设
  • 网站建设重要性班级优化大师app下载学生版
  • 网站开发的几种语言wordpress免费版主题
  • 自己做开箱网站网站信息推广途径包括哪些
  • 提高网站访问速度wordpress 用户名 密码
  • php网站怎么做自适应手机网站建设解决方案
  • 营销网站制作软件公司建设网站需要什么条件
  • vps如何搭建网站制作平台网站方案
  • 宁波网站制作首推蓉胜网络好笋岗网站建设
  • 网站建设网页链接cdn wordpress ip统计