Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Run method in SpringBoot

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to use the Run method in SpringBoot. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

SpringBoot's Run method:

Track the run method of the startup class first

After entering, there is also a run method implemented. Continue to enter.

Here, you can see that there is a SpringApplication constructor, enter

Enter this

The code here is displayed more, analyze it:

The explanation for the source comment is: Create a new instance. Beans from the specified primary source will load the application context

This method is mainly used to determine what type of Web it is in the front, and load the instance later.

Type:

Enter WebApplicationType, there are three types, respectively

REACTIVE, NONE,SERVLET

Used to determine if the class providing the class name exists and can be loaded

If it is a responsive web application org.springframework.web.reactive.DispatcherHandler, you need to load the embedded responsive web server

If there is no javax.servlet.Servlet or org.springframework.web.context.ConfigurableWebApplicationContext, it is not a web application and does not need to load and launch the embedded web server.

If it is a normal servlet web application, you need to load the web server that starts the embedded servlet (such as Tomcat) at startup.

Load instance:

Enter the getSpringFactoriesInstances method:

Continue to enter:

It can be seen that it is loaded according to the name to return the instance, and then enter the loadFactoryNames method:

Enter the loadSpringFactors method:

You can see that it is loaded from FACTORIES_RESOURCE_LOCATION

The spring.factories file is a set of key=value groups containing the full class names with key EnableAutoConfiguration, and value is a comma-separated list of AutoConfiguration class names.

There is also a file spring-autoconfigure-metadata.properties under this file, with loading conditions

@Conditional annotation, which enables some configurations only if certain conditions are met.

@ConditionalOnBean

A Bean is instantiated only if an object exists in the current context.

@ConditionalOnClass

A Bean is instantiated only if a class is on the classpath

@ConditionalOnExpression

A Bean is instantiated when the expression is true.

Among them, EnableAutoConfiguration is used as spring annotation to enable automatic configuration and automatic assembly.

About "how to use the Run method in SpringBoot" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report