springboot类加载顺序,webapplicationinitializer
相信使用过Spring Boot的开发人员很熟悉Spring Boot核心模块提供的spring应用程序类。 SpringApplication类的run ) )方法通常在spring APP应用程序的入口类中调用,以启动spring APP应用程序。
1.1.Spring APP应用程序的条目类和spring应用程序类
1 ) spring APP的入口类
Spring APP应用程序的条目类是spring APP应用程序的部署起点,是spring上下文的部署起点,如@SpringBootApplication和@EnableAutoConfiguration
spring APP应用程序的条目类通常只有一个main ()方法,这与标准的Java APP应用程序相匹配,但可能会使开发人员感到困惑。
spring APP应用程序条目类的主) )方法通常只需调用spring boot spring application类的run ) )方法即可启动该spring APP应用程序。
spring application.run (myspringconfigurationapp.class,args );
其中第一个参数MySpringConfigurationApp.class是spring APP应用程序的条目类。 第二个参数args是用于启动spring APP应用程序的命令行参数,可以在spring APP应用程序中访问。 详细情况将在后面叙述。
2 ) Spring Boot的spring应用程序类
用于启动spring APP应用程序的spring boot spring应用程序类。 基本上,创建并初始化Spring APP应用程序的spring上下文。
缺省情况下,SpringApplication类的run ()方法返回ConfigurableApplicationContext对象。
2.spring应用程序类的其他配置
banner.txt自定义启动LOGO以禁用logospringapplicationapp=newspringapplication (myspringconfigurationapp.class )。 app.setbannermode (banner.mode.off ); App.run(args );
正在启动的可监听事件ApplicationStartingEvent
应用程序环境预准备事件
应用程序权限事件
应用程序修复事件或应用程序修复事件
增强spring应用程序类的CommandLineRunner接口或应用程序runner接口
如果希望在启动spring APP应用程序后执行更多代码,可以定义实现CommandLineRunner接口或ApplicationRunner接口的Spring bean类。
CommandLineRunner接口或ApplicationRunner接口是唯一在SpringApplication.run ()方法执行结束之前调用的http://www.Sina
1 ) CommandLineRunner接口可以作为字符串数组访问spring APP应用程序的启动参数args
@ componentpublicclassmybeanimplementscommandlinerunner (公共语音运行(string . args )//dosomething.}
2 )应用程序运行器接口可以应用程序协议的形式访问APP应用程序的参数args
@ componentpublicclassmybeanimplementsapplicationrunner (公共语音运行) applicationargumentsargs )//dosomething.}
在Spring bean中,通过构造函数访问spring APP应用程序的启动参数args
@ componentpublicclassmybean { @ autowiredpublicmybean (applicationargumentsargs (boolean debug=args.contains option ) '////启动参数'--如果为--debug logfile.txt ',//,则debug=true,files=['logfile.txt'] }}
参考链接:
3358 docs.spring.io/spring-boot/docs/1.5.4.release/reference/html single /