0
0
Spring Bootframework~20 mins

Custom auto-configuration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot Auto-Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Spring Boot custom auto-configuration class is missing @ConditionalOnClass?
Consider a custom auto-configuration class that configures a bean but does not use @ConditionalOnClass. What is the likely behavior when the application starts?
Spring Boot
package com.example.autoconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyAutoConfiguration {

    @Bean
    public String myBean() {
        return "AutoConfiguredBean";
    }
}
AThe bean is never created because @ConditionalOnClass is required.
BThe application fails to start due to missing class errors.
CThe bean is created only if the dependent class is present on the classpath.
DThe bean is always created regardless of whether the dependent class is on the classpath.
Attempts:
2 left
💡 Hint
Think about what @ConditionalOnClass does and what happens if you omit it.
📝 Syntax
intermediate
1:30remaining
Which annotation is required to mark a class as a Spring Boot auto-configuration?
Select the correct annotation to declare a class as an auto-configuration class in Spring Boot.
A@Configuration
B@AutoConfiguration
C@EnableAutoConfiguration
D@SpringBootApplication
Attempts:
2 left
💡 Hint
Auto-configuration classes are regular configuration classes with some extra metadata.
🔧 Debug
advanced
2:30remaining
Why does a custom auto-configuration bean not appear in the application context?
You created a custom auto-configuration class and added it to META-INF/spring.factories but the bean is not available at runtime. What is the most likely cause?
AThe spring.factories file is missing the fully qualified name of the auto-configuration class under the key org.springframework.boot.autoconfigure.EnableAutoConfiguration.
BThe auto-configuration class is missing the @Component annotation.
CThe bean method is private instead of public.
DThe application.properties file disables all auto-configurations.
Attempts:
2 left
💡 Hint
Check the spring.factories file format and keys carefully.
🧠 Conceptual
advanced
2:00remaining
What is the purpose of @ConditionalOnMissingBean in custom auto-configuration?
Why do Spring Boot custom auto-configurations often use @ConditionalOnMissingBean on bean methods?
ATo always override existing beans with the auto-configured bean.
BTo create the bean only if no other bean of the same type is already defined in the context.
CTo prevent the bean from being created under any circumstances.
DTo delay bean creation until explicitly requested.
Attempts:
2 left
💡 Hint
Think about how auto-configuration should behave when user-defined beans exist.
state_output
expert
3:00remaining
What is the output when a custom auto-configuration bean depends on a missing class with @ConditionalOnClass?
Given this custom auto-configuration class: @Configuration @ConditionalOnClass(name = "com.example.ExternalService") public class ExternalServiceAutoConfig { @Bean public String externalServiceBean() { return "ServiceReady"; } } If com.example.ExternalService is NOT on the classpath, what happens when the application starts?
AThe bean externalServiceBean is created with a null value.
BThe bean externalServiceBean is created but throws ClassNotFoundException at runtime.
CThe bean externalServiceBean is NOT created and no error occurs.
DThe application fails to start with a NoClassDefFoundError.
Attempts:
2 left
💡 Hint
Consider what @ConditionalOnClass does when the class is missing.