Complete the code to mark a class as a Spring Boot auto-configuration.
@[1] public class MyAutoConfiguration { }
The @Configuration annotation marks the class as a source of bean definitions for Spring.
Complete the code to conditionally enable the auto-configuration only if a bean of type DataSource is missing.
@ConditionalOnMissingBean([1].class) public class MyAutoConfiguration { }
The @ConditionalOnMissingBean(DataSource.class) annotation ensures the configuration applies only if no DataSource bean exists.
Fix the error in the code to properly register the auto-configuration class in Spring Boot.
META-INF/spring.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=[1]The spring.factories file must list the fully qualified class name without '.class' or file extensions.
Fill both blanks to create a bean method that returns a RestTemplate only if no other RestTemplate bean exists.
@Bean @ConditionalOnMissingBean([1].class) public [2] restTemplate() { return new RestTemplate(); }
The method returns a RestTemplate bean and is conditional on missing RestTemplate beans.
Fill all three blanks to create a conditional auto-configuration that loads only if property 'app.feature.enabled' is true and a bean of type FeatureService is missing.
@ConditionalOnProperty(name = "app.feature.enabled", havingValue = "[1]") @ConditionalOnMissingBean([2].class) @Configuration public class FeatureAutoConfiguration { @Bean public [3] featureService() { return new FeatureService(); } }
The property must be 'true' to enable the config, and the bean type must be FeatureService for both condition and return type.