Spring Framework Spring Boot & Auto-Configuration 2 — Questions and Answers
Question 1: What Spring Boot Actuator endpoint shows the health status of the application?
- /actuator/status
- /actuator/health (Correct answer)
- /actuator/info
- /actuator/ping
Correct answer: /actuator/health
The /actuator/health endpoint aggregates health indicators and returns the overall UP or DOWN status of the application.
Question 2: Which annotation conditionally registers a bean only if another specific bean is present?
- @ConditionalOnProperty
- @ConditionalOnBean (Correct answer)
- @ConditionalOnClass
- @ConditionalOnMissingBean
Correct answer: @ConditionalOnBean
@ConditionalOnBean registers a bean in the context only if one or more specified beans are already present in the BeanFactory.
Question 3: In Spring Boot, what is the purpose of application profiles?
- To define user roles in the application
- To load different configurations based on the active environment (dev, test, prod) (Correct answer)
- To profile application performance
- To manage database connection pools
Correct answer: To load different configurations based on the active environment (dev, test, prod)
Spring profiles allow you to define environment-specific beans and configuration properties, activated via spring.profiles.active.
Question 4: What does the @SpringBootTest annotation do?
- Runs only unit tests for Spring beans
- Loads the full application context for integration testing (Correct answer)
- Mocks the Spring security layer
- Enables performance testing
Correct answer: Loads the full application context for integration testing
@SpringBootTest bootstraps the complete Spring application context for integration tests, making it useful for testing end-to-end behavior.
Question 5: What property sets the embedded server port in Spring Boot?
- spring.server.port
- server.port (Correct answer)
- spring.port
- embedded.server.port
Correct answer: server.port
The server.port property in application.properties configures the port that the embedded server (Tomcat by default) listens on.
Question 6: How do you bind a group of related properties to a Java object in Spring Boot?
- Using @Value on each field individually
- Using @ConfigurationProperties on a class with a prefix (Correct answer)
- Using @PropertyGroup annotation
- Using @BindProperties annotation
Correct answer: Using @ConfigurationProperties on a class with a prefix
@ConfigurationProperties binds external configuration properties with a common prefix to fields of a POJO, enabling type-safe configuration.
What Spring Boot Actuator endpoint shows the health status of the application?