In this paper, a basic springboot, mvc service how to start loading. To explore, to do some exploring record source
First build a normal start of springboot of mvc project.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
@EnableFeignClients @EnableEurekaClient @SpringBootApplication @RestController public class AuthServiceApplication { @RequestMapping("/health") public String home() { return "Hello World"; } public static void main(String[] args) { SpringApplication.run(AuthServiceApplication.class, args); } }
click to enter
SpringApplication.run(AuthServiceApplication.class, args);
run method, continue to click into SpringApplication, constructor.
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) { return new SpringApplication(primarySources).run(args); }
It can be seen entering the following constructor public SpringApplication (ResourceLoader resourceLoader, Class ... primarySources <?>) {This.resourceLoader = resourceLoader; // class loader, this time from above click into found the class loader to null, the code behind specifies the default class loader
Assert.notNull (primarySources, "PrimarySources not the MUST BE null");
this.primarySources new new LinkedHashSet = <> (Arrays.asList (primarySources));
this.webApplicationType = WebApplicationType.deduceFromClasspath (); // Gets the current type of project start , there are three types enumerated: NONE, SERVLET (usually the Java server program), rEACTIVE (reactive and is a fully non-blocking web of the frame, a subsequent inquiry do)
setInitializers ((Collection) getSpringFactoriesInstances (ApplicationContextInitializer.class)); // get the context of the current program to initialize class
setListeners ((Collection) getSpringFactoriesInstances (ApplicationListener.class )); // get all listeners current program
this.mainApplicationClass = deduceMainApplicationClass ();
}
Let's look first focus this.webApplicationType = WebApplicationType.deduceFromClasspath (); see the following access codes (code segment)
1 static WebApplicationType deduceFromClasspath() { 2 if (ClassUtils.isPresent(WEBFLUX_INDICATOR_CLASS, null) && !ClassUtils.isPresent(WEBMVC_INDICATOR_CLASS, null) 3 && !ClassUtils.isPresent(JERSEY_INDICATOR_CLASS, null)) { 4 return WebApplicationType.REACTIVE; 5 } 6 for (String className : SERVLET_INDICATOR_CLASSES) { 7 if (!ClassUtils.isPresent(className, null)) { 8 return WebApplicationType.NONE; 9 } 10 } 11 return WebApplicationType.SERVLET; 12 }
As ClassUtils.isPresent method, enter the code found inside view, will go to load the specified WEBFLUX_INDICATOR_CLASS other categories, if not look for returns false. Then we see the figure, by spring official download quick start webclent project, you can know the pom file need to configure
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
See FIG class source code, you can be found below, and view items referenced above can be obtained jar class code fragment, after the final judgment is returned SERVLET
Similarly, if we configure
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency>
After finding and judgment will eventually get REACTIVE. Interested students can try it yourself to see.