I am working on Spring Boot. I have some doubt
Spring Boot automatically configures your application based on the dependencies you have added to the project by using @EnableAutoConfiguration annotation. For example, if MySQL database is on your classpath, but you have not configured any database connection, then Spring Boot auto-configures an in-memory database.
Spring Boot Annotations is a form of metadata that provides data about a program that is not a part of the program itself. They do not have any direct effect on the operation of the code they annotate. Spring Boot Annotations do not use XML and instead use the convention over configuration principle.
Uses. It's not mandatory to put @SpringBootApplication to create a Spring Boot application, you can still use @Configuration and @EnableAutoConfiguration individually as shown in the example given in the next point.
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 cors 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/**"); } }
Spring boot works with a lot of generic AutoConfiguration
, example DataSourceAutoConfiguration
for DataSource
etc. So that you don't have to do much of the configurations and focus just on business logic. Read this for more
Yes, you can either start a Spring boot application as a Console application or with other web servers like Jetty. Read this for more
You just have to add a FilterRegistrationBean
in your class with main method or any other class with @Configuration
to register a custom Filter
.
@Bean public FilterRegistrationBean crossFilter() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new CrossFilter()); registration.addUrlPatterns("/*"); return registration; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With