简体   繁体   中英

How to find entry point of a Spring Boot application?

What is the entry point of a spring boot application?

While going through a Spring Boot application code, all that it says is there is a code

public static void main having - SpringApplication.run(Application.class, args) 

Example - SpringBoot2RestServiceApplication.java .

But how to get to know what is the entry point, just by going through the code. Earlier, if we go through applicationContext.xml - example - applicationContext.xml , we could understand the flow.

Is there any way, or maybe a standard to follow to make this understanding self-explanatory?

My question was more of understanding the flow of the application than finding the main class. One option could be separating configurations(@Configuration) to a separate class having multiple @Bean annotations, this would help in finding all bean wirings at one place. Is there a standard that large projects use to make code flow understandable?

The easiest thing to do would probably be to search for @SpringBootApplication in your code.

But, a guaranteed way to get this information would be to build the Spring Boot JAR. From there, you can open the resulting JAR and find the main class defined in the manifest, under META-INF/MANIFEST.MF . You'll see it under the Start-Class attribute:

Start-Class: com.example.foo.Application

I think the OP is studying an existing Spring Boot application, and is asking how to locate any runner, such as Application Runners, Command Line Runners, MVC controllers, Rest controllers, etc.

I don't know if there is an easy way to locate those, unless they are grouped together in the original design.

It's a difficult problem to do programmatically, because threads can be launched outside of Spring, for example in a constructor or a @PostConstruct.

It would be nice though if there were IDE support to easily locate anything that gets launched by Spring Boot

search @SpringBootApplication annotation in your project, the class with @SpringBootApplication annotation will automatically do the component-scan for the sub packages.

if no @SpringBootApplication annotation found, search the class extending "SpringBootServletInitializer" which is also a starting point for the spring boot application

The Entry of any spring boot application has an annotation of @SpringBootApplication

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM