Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Do You Know These 7 Advance Spring Boot Annotations?

--

Spring Boot provides many annotations to make development efficient and clean. While we know about some of the basic annotations, like @RestController, @Autowired, etc.

I am going to discuss some of the less-used Spring Boot annotations that can significantly enhance your development.

My articles are free for everyone. Non-members can read this full article for free HERE.

@Conditional

Various annotations in the @Conditional family allow us to conditionally include beans in application content based on a filter.

@ConditionalOnProperty

This annotation enables a bean only if a particular property has a specific value.

@Configuration
public class FeatureConfig {

@Bean
@ConditionalOnProperty(name = "feature.enabled", havingValue = "true")
public LoggingService loggingService() {
return new LoggingService();
}
}

@ConditionalOnBean and @ConditionalOnMissingBean

We use this annotation to create beans depending on whether other beans are present.

@Configuration
public class CacheConfiguration {

@Bean
@ConditionalOnMissingBean
public…
Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Saquib Aftab
Saquib Aftab

Written by Saquib Aftab

Lead Software Engineer | Java | Technology | Productivity | Learning and Improving to become a better developer

Responses (2)