Logo

dev-resources.site

for different kinds of informations.

Spring Boot: About @SpringBootApplication

Published at
1/7/2025
Categories
spring
springboot
Author
saladlam
Categories
2 categories in total
spring
open
springboot
open
Author
8 person written this
saladlam
open
Spring Boot: About @SpringBootApplication

Following is the definition. For following discussion assumes that the class com.example.app.TestApplication annotated with @SpringBootApplication.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
        @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
  // ...
}
Enter fullscreen mode Exit fullscreen mode

@EnableAutoConfiguration annotation

@EnableAutoConfiguration means to lookup org.springframework.boot.autoconfigure.EnableAutoConfiguration entry from \META-INF\spring.factories file of all jar files. Following is one of the entries.

# spring-boot-autoconfigure-2.6.11.jar!\META-INF\spring.factories
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
# ...
Enter fullscreen mode Exit fullscreen mode

Specified AutoConfiguration classes coming from different files will be merged, imported to ApplicationContext and processed after finishing processing @Configuration classes. Spoken behaviour is controlled by org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.

@AutoConfigurationPackage annotation

@AutoConfigurationPackage is annotated in @EnableAutoConfiguration. This is for saving the path of base package (in this example com.example.app) and allow other configuration class (such as Spring Data) to scan annotation which is not handled by @ComponentScan. (In case of Spring Data, @Repository. Although it is annotated with @Component, but @Repository is annotated in interface that will not be processed by @ComponentScan.)

@SpringBootConfiguration annotation

Same behaviour as @Configuration, in addition that any properties defined will be merged into test class and will not be affected by the existence of @AutoConfigureXXX annotation.

@ComponentScan annotation

Scan component from base package (in this example com.example.app) and all childs. Exclude AutoConfiguration class found by @EnableAutoConfiguration (controlled by org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter) and child filter of TypeExcludeFilter (controlled by org.springframework.boot.context.TypeExcludeFilter).

spring Article's
30 articles in total
Favicon
Launched a Web version of my Project using Java Spring Framework, Spring Boot Web
Favicon
Developing a project using Java Spring Framework, JSON, JPA and PostgreSQL
Favicon
Волшебные скоупы: Как Spring организует работу бинов
Favicon
Quando usar ResponseEntity?
Favicon
What is load balancing and how to do it on client side
Favicon
Capturing and Testing Logs in Java with SLF4J and Logback: A Simple Guide
Favicon
Can you find the Output of this Java Code
Favicon
Ways to Speed Up Spring Boot Application Startup Time
Favicon
Apache wicket with spring boot example application: notice board
Favicon
Handling the "Forwarded" Header in Spring Boot Applications
Favicon
About UriComponentsBuilder and UriComponents
Favicon
Spring Boot: About @SpringBootApplication
Favicon
Spring Security: CSRF protection
Favicon
ISBN Stacks — A look at a possible Spring Application implementation without annotations
Favicon
spring profiles dev production
Favicon
Learn Spring Data JPA, Part - 1
Favicon
Methods for Efficient Large File Processing in Spring Boot
Favicon
Hexagonal Architecture — A Favorite Lyrics Spring Boot — Java Example
Favicon
Validation in Spring REST Framework (SRF)
Favicon
spring
Favicon
Spring Security: Redirect to login page if access pages which is for authorized user only
Favicon
Lambda vs. Named Functions: Choosing the Right Tool for the Job
Favicon
Techniques for Mastering Spring Interceptors: Detailed Guide with Examples
Favicon
Techniques for Using @NoRepositoryBean in Spring Data JPA: A Comprehensive Guide
Favicon
Understanding the Spring Framework: A Developer’s Journey to Clean Code 🚀
Favicon
@PreConstruct and @PostConstruct annotation Spring Boot Example
Favicon
Java’s Functional Programming: the OOP influence
Favicon
🧪 Тестирование с TestRestTemplate и MockMvc: миссия "Котики против багов" 🐞
Favicon
spring boot
Favicon
Reasons to Use WireMock for Testing REST APIs in Spring Boot Applications

Featured ones: