How Spring Boot Application works internally?

Sangram Badi :

I am working on Spring Boot. I have some doubt

  1. As i know spring boot has a main() and it calls static run() which is present in SpringApplication. But i want to know what is the flow of Spring boot application ?
  2. Can we run spring boot application on server other than tomcat, if yes how ?
  3. How to add CROSS Filter in Spring boot application ? As we know in Spring MVC application we configure CROSS Filter in web.xml, but Spring boot we don't have web.xml, So how to configure this ?
Vijender Kumar :

Following is the high-level flow of how spring boot works.

From the run method, the main application context is kicked off which in turn searches for the classes annotated with @Configuration, initializes all the declared beans in those configuration classes, and based upon the scope of those beans, stores those beans in JVM, specifically in a space inside JVM which is known as IOC container. After the creation of all the beans, automatically configures the dispatcher servlet and registers the default handler mappings, messageConverts, and all other basic things.

Basically, spring boot supports three embedded servers:- Tomcat (default), Jetty and Undertow.

You can add cross filters in spring boot in one of the configuration files as

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**");
    }
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=422009&siteId=1