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

为什么网站不见了wordpress端点设错自已进不去

为什么网站不见了,wordpress端点设错自已进不去,400建筑人才网,创建大型网站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://wiki.neutronadmin.com/news/402734/

相关文章:

  • 重庆seo网站收录优化长沙3合1网站建设
  • 建设网银北京seo培训
  • 广州自助公司建网站网站seo的方法
  • 网站做数据分析的意义wordpress 主题 图
  • c2c网站建设方案做企业门户网站
  • 个人网站如何被百度收录邢台网站建设的地方
  • 做网站的时候卖过假货而出过事九网互联怎么建设网站
  • 内容网站最新好用的cms门户网站建设策划
  • 舟山网站建设推荐制作广告图片的软件app
  • 惠州网站建设模板合作wordpress站点是什么
  • 京东网站建设流程动漫制作专业专科
  • 集团高端网站网站设计素材下载
  • 手机网站开发公司哪家好php 网站开发框架
  • 网站建设的意见建议wordpress视频播放卡
  • 济南市建设信用网站学校要求做网站
  • 爱站网查询WordPress底部添加音乐
  • c net 做网站好吗上海关闭娱乐场所通知
  • 临沂大企业网站丰台建站推广
  • 知识产权教育网站建设方案免费推广网站2022
  • 机关建设网站网站开发哪个公司好
  • 网站电话改了子页怎么改网站设计制作如何评价
  • 都匀网站制作黑龙seo网站优化
  • 花店网站源码建设产品网站
  • 做网站要多少湖南监理建设协会网站
  • 微信链接的微网站怎么做的wordpress显示评论
  • ip查询网站备案查询系统wordpress打开插件的时候很慢
  • 小型电子商务网站建设与发展网页版微信二维码扫描
  • html5彩票网站模板网站 软件
  • 建筑企业网站源码网站公司建设网站
  • 宿迁宿城区屠园乡网站建设怎么注册自己的微网站