Spring Boot Specific
About
Spring Boot provides several annotations that simplify configuration, auto-configuration, and conditional bean loading.
1. Core Spring Boot Annotations
These annotations help in configuring and bootstrapping a Spring Boot application.
@SpringBootApplication
@SpringBootApplication
This is the main entry point for a Spring Boot application.
It is a combination of:
@Configuration
– Marks the class as a Spring configuration class.@EnableAutoConfiguration
– Enables automatic configuration based on dependencies.@ComponentScan
– Scans for components in the same package and sub-packages.
@EnableAutoConfiguration
@EnableAutoConfiguration
Enables Spring Boot’s auto-configuration feature, which automatically configures beans based on the classpath.
It is included in
@SpringBootApplication
.
2. Conditional Annotations
These annotations conditionally enable or disable beans based on various criteria.
@ConditionalOnProperty
@ConditionalOnProperty
Loads a bean only if a specified property exists in
application.properties
orapplication.yml
.
@ConditionalOnClass
@ConditionalOnClass
Loads a bean only if a specified class is present in the classpath.
@ConditionalOnMissingBean
@ConditionalOnMissingBean
Registers a bean only if no other bean of the same type exists.
@ConditionalOnBean
@ConditionalOnBean
Registers a bean only if another specified bean exists.
Last updated
Was this helpful?