SpringBoot MCQ
SpringBoot MCQ
**@SpringBootApplication**:
2. **@Controller**:
- Marks a class as a controller in Spring MVC, responsible for handling HTTP requests and
returning views or data to clients.
- Works with @RequestMapping to map request URLs to handler methods within the
controller.
3. **@RestController**:
- Simplifies the development of REST APIs by automatically serializing return values to JSON
or XML.
4. **@RequestMapping**:
- Maps HTTP requests to handler methods in a controller class, allowing developers to specify
URL paths and HTTP methods.
5. **@Autowired**:
6. **@Service**:
- Marks a class as a service component in the business logic layer, encapsulating business
logic, transaction management, and other non-web-related functionalities.
7. **@Repository**:
- Indicates that a class is a data access component, typically used to interact with databases
or other data sources.
8. **@Component**:
9. **@Configuration**:
- Provides bean definitions and configuration to the Spring application context, allowing for
Java-based configuration as an alternative to XML configuration.
10. **@Bean**:
- Declares a bean within a @Configuration class, providing a way to define and configure
beans explicitly.
11. **@Profile**:
- Allows conditional bean registration based on active profiles in the application context,
enabling different configurations for different environments.
12. **@Value**:
- Injects values from property files, environment variables, or other sources into
Spring-managed beans, allowing for externalized configuration.
13. **@Qualifier**:
- Resolves ambiguity during autowiring by specifying the name of the bean to be injected.
14. **@Scope**:
- Specifies the scope (lifecycle) of a bean in the Spring application context, controlling how
and when bean instances are created, reused, and destroyed.
15. **@Async**:
16. **@EnableScheduling**:
- Enables support for scheduling tasks within a Spring application, allowing methods
annotated with @Scheduled to be executed according to a specified schedule.
17. **@EnableAspectJAutoProxy**:
- Enables support for AspectJ-based annotation-driven aspect configuration, allowing for the
creation and execution of aspects to encapsulate cross-cutting concerns.
18. **@EnableJms**:
19. **@EnableWebSocketMessageBroker**:
- Enables WebSocket messaging with support for a message broker configuration, providing
support for handling WebSocket messages and managing WebSocket connections in Spring
MVC applications.
20. **@EnableResourceServer**:
21. **@EnableAuthorizationServer**:
22. **@EnableBatchProcessing**:
- Enables support for batch processing within a Spring application, providing infrastructure for
defining and executing batch jobs.
23. **@EnableWebMvc**:
- Enables Spring MVC configuration in a Spring Boot application, allowing for customizing
and extending Spring MVC features.
24. **@EnableJdbcHttpSession**:
25. **@Conditional**:
26. **@ConditionalOnClass**:
- Registers a bean only if a specific class is present in the classpath, enabling dynamic bean
registration based on dependencies.
27. **@ConditionalOnProperty**:
28. **@ConditionalOnMissingBean**:
- Registers a bean only if there is no existing bean of the same type, providing default
implementations or fallbacks when a bean is not explicitly defined.
29. **@ConditionalOnExpression**:
30. **@PropertySource**:
- Specifies the location of property files to be loaded into the Spring environment, allowing for
externalized configuration.
31. **@ComponentScan**:
32. **@Import**:
- Imports additional configuration classes into the current configuration class, allowing for
modularization and composition of configuration.
33. **@ImportResource**:
- Imports XML-based Spring configuration files into the application context, allowing for
integrating existing XML-based configuration with Java-based configuration.
34. **@EnableAutoConfiguration**:
35. **@EnableDiscoveryClient**:
- Enables service discovery functionality for applications using Spring Cloud, allowing the
application to register itself with a service registry.
36. **@EnableEurekaServer**:
- Configures the application as a Eureka service registry server, enabling service registration,
discovery, and health monitoring for other services.
37. **@EnableFeignClients**:
- Enables Feign client functionality for applications using Spring Cloud, simplifying the
creation of REST clients by allowing developers to define interfaces annotated with
@FeignClient.
38. **@FeignClient**:
- Declares a REST client interface for Feign, specifying the name of the target service and the
URL patterns for the REST endpoints.
39. **@EnableZuulProxy**:
- Enables Zuul proxy functionality for applications using Spring Cloud, providing a gateway
service for routing requests to backend services based on configured routes.
40. **@EnableConfigServer**:
41. **@EnableHystrix**:
- Enables Hystrix circuit breaker functionality for applications using Spring Cloud, providing
fault tolerance and resilience by isolating and handling failures in distributed systems.
42. **@EnableHystrixDashboard**:
Enables the Hystrix Dashboard for monitoring Hystrix metrics, providing a graphical user
interface for visualizing circuit breaker states and metrics.
43. **@EnableCircuitBreaker**:
44. **@EnableRetry**:
- Enables automatic retry functionality for methods, allowing for the automatic retrying of
failed operations based on configurable retry policies.
45. **@EnableWebSecurity**:
- Enables Spring Security's web security features for the application, allowing developers to
configure authentication, authorization, and CSRF protection.
46. **@EnableGlobalMethodSecurity**:
- Enables method-level security for Spring Security, allowing developers to apply security
annotations such as @Secured and @PreAuthorize to controller methods.
47. **@EnableJpaRepositories**:
- Enables Spring Data JPA repositories for the application, providing CRUD operations and
query methods for interacting with a relational database using JPA.
48. **@EnableTransactionManagement**:
- Enables Spring's transaction management features for the application, allowing developers
to annotate methods with @Transactional to specify transactional behavior.
49. **@Entity**:
50. **@Table**:
- Specifies the database table associated with an entity class, allowing developers to
customize table properties such as name, schema, and constraints.
51. **@Id**:
- Marks a field as the primary key of an entity, defining the unique identifier for database
records and ensuring object identity within the persistence context.
52. **@GeneratedValue**:
- Specifies the strategy for generating primary key values automatically, allowing developers
to configure how primary key values are assigned to entity instances.
53. **@Column**:
- Specifies the mapping between an entity field and a database column, providing
fine-grained control over the database schema generated by ORM frameworks.
54. **@OneToMany**:
55. **@ManyToOne**:
- Defines a many-to-one relationship between entities, representing the owning side of the
association and typically used to model parent-child relationships.
56. **@JoinTable**:
- Specifies the join table for a many-to-many relationship between entities, allowing
developers to map a many-to-many association by defining an intermediate table.
57. **@Transactional**:
58. **@Cacheable**:
- Marks a method's return value for caching, allowing for the storage of method results in the
cache for improved performance and efficiency.
59. **@CachePut**:
- Updates the value in the cache for a method regardless of the cache's current contents,
useful for updating cached data when the underlying data changes.
60. **@CacheEvict**:
- Removes entries from the cache to maintain consistency between cached data and the
underlying data source, allowing for the invalidation of cached data.
61. **@Valid**:
- Indicates that a method parameter should be validated against constraints defined in its
associated bean validation annotations, providing data integrity and validation.
62. **@Validated**:
63. **@PathVariable**:
- Binds a method parameter to a URI template variable in a Spring MVC controller, allowing
developers to extract variable values from the request URI.
64. **@RequestBody**:
- Binds the body of a HTTP request to a method parameter in a Spring MVC controller,
converting the request body to the specified parameter type.
65. **@ResponseBody**:
- Indicates that a method return value should be serialized directly into the HTTP response
body, useful for returning data directly from controller methods.
66. **@ModelAttribute**:
- Binds a method parameter to a model attribute in a Spring MVC controller, adding the
annotated parameter to the model before rendering a view.
67. **@ExceptionHandler**:
- Defines a method to handle exceptions thrown during request processing in a Spring MVC
controller, allowing for centralized exception handling logic.
68. **@ControllerAdvice**:
- Marks a class as a global controller advice, providing centralized exception handling for all
controllers in the application.
69. **@CrossOrigin**:
- Configures cross-origin resource sharing (CORS) for Spring MVC controllers, allowing for
enabling cross-origin requests from web browsers to backend APIs.
70. **@EnableSwagger2**:
- Enables Swagger support for documenting and testing RESTful APIs in a Spring Boot
application, providing a user-friendly interface for exploring and interacting with API endpoints.
71. **@ApiOperation**:
73. **@ApiResponse**:
74. **@EnableConfigurationProperties**:
- Enables support for binding external configuration properties to Spring beans, allowing for
externalized configuration and injecting properties into Spring components.
75. **@RequestBodyAdvice**:
- Intercepts and customizes HTTP request bodies before they are bound to method
parameters in Spring MVC controllers, allowing for preprocessing or validation of request
bodies.
76. **@ResponseBodyAdvice**:
- Intercepts and customizes HTTP response bodies before they are serialized and sent to
clients in Spring MVC controllers, allowing for preprocessing or modification of response bodies.
77. **@EventListener**:
- Marks a method as an event listener, allowing it to receive and handle application events,
providing a convenient mechanism for implementing event-driven architectures.
78. **@Scheduled**:
79. **@Retryable**:
- Indicates that a method should be retried automatically if it fails due to a specified exception,
providing resilience and improving the reliability of critical operations.
Basic Level
1. What is Spring Boot primarily used for?
- A. Building Android applications
- B. Creating web applications in Java
- C. Developing desktop applications
- D. Building machine learning models
- **Answer: B. Creating web applications in Java**
2. Which annotation is used to mark the main class in a Spring Boot application?
- A. @MainClass
- B. @SpringBootApplication
- C. @StartClass
- D. @MainApplication
- **Answer: B. @SpringBootApplication**
9. How does Spring Boot simplify the creation of RESTful web services?
- A. By providing annotations like @RestController
- B. By generating code based on configuration
- C. By automatically configuring servlets
- D. By abstracting away HTTP protocols
- **Answer: A. By providing annotations like @RestController**
14. What is the purpose of the application.properties (or application.yml) file in Spring Boot?
- A. To define application-specific properties
- B. To configure datasource properties
- C. To set logging levels
- D. All of the above
- **Answer: D. All of the above**
29. How does Spring Boot simplify the creation of command-line applications?
- A. By providing annotations like @CommandLineApp
- B. By generating code based on configuration
- C. By providing a SpringApplication class
- D. All of the above
- **Answer: C. By providing a SpringApplication class**
31. How does Spring Boot simplify the creation of database connections?
- A. By providing built-in support for JDBC
- B. By automatically configuring datasource beans
- C. By generating SQL queries from entity classes
- D. All of the above
- **Answer: D. All of the above**
39. How does Spring Boot simplify the creation of scheduled tasks?
- A. By providing annotations like @Scheduled
- B. By generating code based on configuration
- C. By automatically configuring task schedulers
- D. All of the above
- **Answer: A. By providing annotations like @Scheduled**
Intermediate Level
10. How does Spring Boot simplify the creation of RESTful clients?
- A. By providing annotations like @RestClient
- B. By using the RestTemplate class
- C. By automatically generating client code
- D. By providing built-in support for Apache HttpClient
- **Answer: B. By using the RestTemplate class**
12. How does Spring Boot handle application properties in YAML format?
- A. By providing a dedicated YAML configuration class
- B. By using the @YamlPropertySource annotation
- C. By reading properties from application.yml files
- D. All of the above
- **Answer: C. By reading properties from application.yml files**
16. How does Spring Boot simplify the creation of CRUD operations?
- A. By providing default implementations for repository interfaces
- B. By generating SQL queries from entity classes
- C. By using the @CrudRepository annotation
- D. All of the above
- **Answer: D. All of the above**
24. How does Spring Boot simplify the creation of scheduled tasks?
- A. By providing annotations like @Scheduled
- B. By generating code based on configuration
- C. By automatically configuring task schedulers
- D. All of the above
- **Answer: A. By providing annotations like @Scheduled**
26. How does Spring Boot simplify integration testing with external services?
- A. By providing built-in support for WireMock
- B. By automatically configuring test environments
- C. By using embedded databases for testing
- D. All of the above
- **Answer: A. By providing built-in support for WireMock**
34. How does Spring Boot simplify the configuration of embedded databases?
- A. By providing built-in support for H2 Database
- B. By using embedded-database.properties files
- C. By automatically configuring datasource beans
- D. All of the above
- **Answer: C. By automatically configuring datasource beans**
35. What is
36. How does Spring Boot simplify integration testing with external services?
- A. By providing built-in support for WireMock
- B. By automatically configuring test environments
- C. By using embedded databases for testing
- D. All of the above
- **Answer: A. By providing built-in support for WireMock**
Advanced Level
1. Which annotation is used to enable Spring Data JPA repositories in a Spring Boot
application?
- A. @EnableJpaRepositories
- B. @EnableTransactionManagement
- C. @EnableAutoConfiguration
- D. @EnableWebMvc
- **Answer: A. @EnableJpaRepositories**
4. Which dependency is commonly used for integrating Spring Boot applications with Apache
Kafka?
- A. spring-kafka
- B. spring-cloud-starter-stream-kafka
- C. spring-boot-starter-web
- D. spring-boot-starter-actuator
- **Answer: A. spring-kafka**
9. How can you customize the error response format in a Spring Boot RESTful API?
- A. By providing a custom exception handler with @ControllerAdvice
- B. By configuring error properties in application.yml
- C. By using the @ErrorFormat annotation
- D. By extending the ResponseEntity class
- **Answer: A. By providing a custom exception handler with @ControllerAdvice**
10. Which annotation is used to enable distributed tracing in Spring Boot applications?
- A. @EnableDistributedTracing
- B. @EnableZipkinTracing
- C. @EnableSleuth
- D. @EnableTrace
- **Answer: C. @EnableSleuth**
12. Which annotation is used to enable Spring Security in a Spring Boot application?
- A. @EnableWebSecurity
- B. @EnableSecurity
- C. @EnableAuthentication
- D. @EnableSecure
- **Answer: A. @EnableWebSecurity**
14. How can you configure a custom banner for a Spring Boot application?
- A. By providing a banner.txt file in the resources directory
- B. By
configuring banner properties in application.yml
- C. By using the @Banner annotation
- D. By extending the Banner interface
- **Answer: A. By providing a banner.txt file in the resources directory**
16. How can you configure an embedded Tomcat server to use a custom SSL certificate in a
Spring Boot application?
- A. By configuring server.ssl properties in application.properties
- B. By providing a keystore file and configuring server.ssl properties
- C. By using the @EnableSsl annotation
- D. By extending the TomcatEmbeddedServletContainerFactory class
- **Answer: B. By providing a keystore file and configuring server.ssl properties**
18. Which dependency is commonly used for integrating Spring Boot applications with
Elasticsearch?
- A. spring-boot-starter-elasticsearch
- B. spring-boot-starter-data-elasticsearch
- C. spring-elasticsearch
- D. elasticsearch-spring-boot-starter
- **Answer: B. spring-boot-starter-data-elasticsearch**
19. How can you configure logging levels for different packages in a Spring Boot application?
- A. By using the @LogLevel annotation
- B. By providing logging properties in application.properties
- C. By using the @Logger annotation
- D. By extending the Logger class
- **Answer: B. By providing logging properties in application.properties**
20. Which annotation is used to enable caching in a Spring Boot application?
- A. @EnableCaching
- B. @EnableCache
- C. @EnableCacheManagement
- D. @EnableSpringCache
- **Answer: A. @EnableCaching**
21. How does Spring Boot simplify the configuration of WebSocket endpoints?
- A. By using the @WebSocketEndpoint annotation
- B. By providing built-in support for STOMP over WebSocket
- C. By configuring WebSocket properties in application.properties
- D. By extending the WebSocketConfigurer interface
- **Answer: B. By providing built-in support for STOMP over WebSocket**
23. Which annotation is used to enable server-sent events (SSE) in a Spring Boot application?
- A. @EnableSse
- B. @EnableSseSupport
- C. @EnableServerSentEvents
- D. @EnableEventSource
- **Answer: B. @EnableSseSupport**
24. How can you configure Spring Boot to use a custom Jackson ObjectMapper?
- A. By providing custom ObjectMapper properties in application.properties
- B. By using the @JsonMapper annotation
- C. By configuring ObjectMapper beans in a @Configuration class
- D. By extending the JacksonObjectMapper class
- **Answer: C. By configuring ObjectMapper beans in a @Configuration class**
28. How can you configure Spring Boot to use a custom authentication provider?
- A. By providing authentication properties in application.properties
- B. By using the @AuthenticationProvider annotation
- C. By extending the AuthenticationProvider interface
- D. By configuring authentication beans in a @Configuration class
- **Answer: D. By configuring authentication beans in a @Configuration class**
29. Which annotation is used to enable HTTP/2 support in a Spring Boot application?
- A. @EnableHttp2
- B. @EnableHttp2Support
- C. @EnableHttp2Protocol
- D. @EnableHttp2Server
- **Answer: B. @EnableHttp2Support**
31. How can you enable HTTP compression in a Spring Boot application?
- A. By configuring server.compression properties in application.properties
- B. By using the @EnableHttpCompression annotation
- C. By providing compression properties in application.yml
- D. HTTP compression is enabled by default in Spring Boot
- **Answer: A. By configuring server.compression properties in application.properties**
35. How can you customize the JSON serialization format for specific properties in a Spring
Boot application?
- A. By using custom serializers with Jackson ObjectMapper
- B. By providing serialization properties in application.properties
- C. By using annotations like @JsonFormat
- D. By extending the JsonProperty class
- **Answer: A. By using custom serializers with Jackson ObjectMapper**
37. How can you configure Spring Boot to use a custom authentication filter?
- A. By using the @CustomAuthenticationFilter annotation
- B. By extending the AbstractAuthenticationProcessingFilter class
- C. By providing authentication filter properties in application.yml
- D. By configuring authentication filters in a @Configuration class
- **Answer: B. By extending the AbstractAuthenticationProcessingFilter class**
38. Which annotation is used to enable metrics collection in a Spring Boot application?
- A. @EnableMetrics
- B. @EnableActuator
- C. @EnableMetricsCollection
- D. @EnableMicrometerMetrics
- **Answer: D. @EnableMicrometerMetrics**
40. How can you enable HTTP/2 support in a Spring Boot application?
- A. By configuring server.http2.enabled property in application.properties
- B. By using the @EnableHttp2 annotation
- C. By providing HTTP/2 properties in application.yml
- D. HTTP/2 support is enabled by default in Spring Boot
- **Answer: A. By configuring server.http2.enabled property in application.properties**
3. What is the correct syntax for injecting a bean using constructor-based dependency injection
in Spring Boot?
- A. `@Autowired public MyClass(MyDependency dependency) { this.dependency =
dependency; }`
- B. `@Inject public MyClass(MyDependency dependency) { this.dependency = dependency; }`
- C. `@Autowired public void setDependency(MyDependency dependency) { this.dependency
= dependency; }`
- D. `@Inject public void setDependency(MyDependency dependency) { this.dependency =
dependency; }`
- **Answer: A. `@Autowired public MyClass(MyDependency dependency) { this.dependency =
dependency; }`**
4. Which of the following annotations is used to specify the base package for component
scanning in a Spring Boot application incorrectly?
- A. `@ComponentScan(basePackages = "com.example")`
- B. `@ComponentScan(basePackages = {"com.example"})`
- C. `@ComponentScan("com.example")`
- D. `@ComponentScan(basePackageClasses = {MyComponent.class})`
- **Answer: C. `@ComponentScan("com.example")`**
5. What is the correct syntax for defining a JPA repository interface in Spring Boot?
- A. `public interface UserRepository extends JpaRepository<User, Long> { }`
- B. `public class UserRepository extends JpaRepository<User, Long> { }`
- C. `@Repository public interface UserRepository extends JpaRepository<User, Long> { }`
- D. `@Service public interface UserRepository extends JpaRepository<User, Long> { }`
- **Answer: A. `public interface UserRepository extends JpaRepository<User, Long> { }`**
6. Which annotation is used to specify the primary bean among multiple candidates of the same
type?
- A. `@Primary`
- B. `@Main`
- C. `@First`
- D. `@Priority`
- **Answer: A. `@Primary`**
7. What is the correct syntax for defining a request mapping for a RESTful endpoint in Spring
Boot?
- A. `@RequestMapping("/endpoint")`
- B. `@Mapping("/endpoint")`
- C. `@Get("/endpoint")`
- D. `@PostMapping("/endpoint")`
- **Answer: A. `@RequestMapping("/endpoint")`**
8. Which of the following annotations is incorrectly formatted for specifying a property value in
Spring Boot?
- A. `@Value("${my.property}")`
- B. `@PropertySource("classpath:application.properties")`
- C. `@ConfigurationProperties(prefix = "my")`
- D. `@Property("${my.property}")`
- **Answer: D. `@Property("${my.property}")`**
9. What is the correct syntax for defining a transactional method in a Spring Boot service class?
- A. `@Transactional public void myMethod() { }`
- B. `public void myMethod() { @Transactional }`
- C. `@Transaction public void myMethod() { }`
- D. `@Transaction public void myMethod() { @Transactional }`
- **Answer: A. `@Transactional public void myMethod() { }`**
10. Which of the following annotations is used to enable caching in a Spring Boot application?
- A. `@EnableCache`
- B. `@EnableCaching`
- C. `@EnableCached`
- D. `@EnableCaches`
- **Answer: B. `@EnableCaching`**
11. What is the correct syntax for defining a Scheduled task method in Spring Boot?
- A. `@Scheduled public void myTask() { }`
- B. `@Schedule public void myTask() { }`
- C. `@ScheduleTask public void myTask() { }`
- D. `@ScheduledTask public void myTask() { }`
- **Answer: A. `@Scheduled public void myTask() { }`**
12. Which annotation is used to enable Spring Boot's TestRestTemplate for integration testing?
- A. `@EnableTestRestTemplate`
- B. `@EnableRestTemplateTest`
- C. `@RestTemplateTest`
- D. `@TestRestTemplate`
- **Answer: D. `@TestRestTemplate`**
13. What is the correct syntax for configuring an embedded Tomcat server's port in
application.properties?
- A. `server.port=8080`
- B. `spring.port=8080`
- C. `embedded.server.port=8080`
- D. `tomcat.server.port=8080`
- **Answer: A. `server.port=8080`**
14. Which annotation is used to define the entry point of a Spring Boot application for testing
purposes?
- A. `@TestEntryPoint`
- B. `@SpringBootTest`
- C. `@BootApplicationTest`
- D. `@EntryPointTest`
- **Answer: B. `@SpringBootTest`**
15. What is the correct syntax for defining a custom banner for a Spring Boot application in
application.properties?
- A. `spring.banner.location=banner.txt`
- B. `spring.boot.banner=banner.txt`
- C. `spring.banner.text=banner.txt`
- D. `spring.application.banner=banner.txt`
- **Answer: A. `spring.banner.location=banner.txt`**
16. Which of the following annotations is used to enable Spring Boot's Actuator module for
monitoring and managing the application?
- A. `@EnableMonitoring`
- B. `@EnableManagement`
- C. `@EnableActuator`
- D. `@EnableMetrics`
- **Answer: C. `@EnableActuator`**
17. What is the correct syntax for specifying a property value placeholder in Spring Boot's
application.properties file?
- A. `my.property=value`
- B. `${my.property=value}`
- C. `${
my.property=value}`
- D. `{my.property=value}`
- **Answer: A. `my.property=value`**
18. Which annotation is used to define a custom error handler for a specific exception type in
Spring Boot?
- A. `@ExceptionHandler`
- B. `@ErrorHandling`
- C. `@HandleError`
- D. `@Error`
- **Answer: A. `@ExceptionHandler`**
19. What is the correct syntax for defining a custom property in Spring Boot's
application.properties file?
- A. `custom.property=value`
- B. `property.custom=value`
- C. `property.custom: value`
- D. `custom:property=value`
- **Answer: A. `custom.property=value`**
20. Which annotation is used to enable asynchronous processing of method calls in Spring
Boot?
- A. `@EnableAsync`
- B. `@Async`
- C. `@EnableAsynchronous`
- D. `@Asynchronous`
- **Answer: A. `@EnableAsync`**
21. What is the correct syntax for defining a custom configuration class in Spring Boot?
- A. `@Configuration public class MyConfig { }`
- B. `@Config public class MyConfig { }`
- C. `@EnableConfiguration public class MyConfig { }`
- D. `@Configurable public class MyConfig { }`
- **Answer: A. `@Configuration public class MyConfig { }`**
22. Which annotation is used to configure logging levels for different packages in a Spring Boot
application?
- A. `@LogLevel`
- B. `@LogConfig`
- C. `@Logging`
- D. `@Slf4j`
- **Answer: A. `@LogLevel`**
23. What is the correct syntax for defining a custom profile in Spring Boot's
application.properties file?
- A. `spring.profiles.active=my-profile`
- B. `profiles.active=my-profile`
- C. `active.profile=my-profile`
- D. `profile=my-profile`
- **Answer: A. `spring.profiles.active=my-profile`**
24. Which annotation is used to specify the base package for component scanning in a Spring
Boot application?
- A. `@ComponentScan`
- B. `@ScanComponents`
- C. `@BasePackage`
- D. `@ComponentBase`
- **Answer: A. `@ComponentScan`**
25. What is the correct syntax for defining a custom property source in Spring Boot?
- A. `@PropertySource("classpath:custom.properties")`
- B. `@PropertySource("custom.properties")`
- C. `@Property("classpath:custom.properties")`
- D. `@Property("custom.properties")`
- **Answer: A. `@PropertySource("classpath:custom.properties")`**
26. Which annotation is used to enable server-sent events (SSE) support in a Spring Boot
application?
- A. `@EnableSse`
- B. `@EnableSseSupport`
- C. `@EnableServerSentEvents`
- D. `@EnableEventSource`
- **Answer: B. `@EnableSseSupport`**
27. What is the correct syntax for defining a custom message converter in Spring Boot's
configuration class?
- A. `@Bean public MyMessageConverter messageConverter() { }`
- B. `@MessageConverter public MyMessageConverter messageConverter() { }`
- C. `@Converter public MyMessageConverter messageConverter() { }`
- D. `@CustomConverter public MyMessageConverter messageConverter() { }`
- **Answer: A. `@Bean public MyMessageConverter messageConverter() { }`**
28. Which annotation is used to enable HTTP compression in a Spring Boot application?
- A. `@EnableCompression`
- B. `@EnableHttpCompression`
- C. `@EnableGzip`
- D. `@EnableDeflate`
- **Answer: B. `@EnableHttpCompression`**
29. What is the correct syntax for defining a custom error page in Spring Boot's
application.properties file?
- A. `error.page=/error`
- B. `error.page.location=/error`
- C. `error.page.redirect=/error`
- D. `error.page.mapping=/error`
- **Answer: A. `error.page=/error`**
30. Which annotation is used to enable HTTP/2 support in a Spring Boot application?
- A. `@EnableHttp2`
- B. `@EnableHttp2Support`
- C. `@EnableHttp2Protocol`
- D. `@EnableHttp2Server`
- **Answer: B. `@EnableHttp2Support`**
31. What is the correct syntax for defining a custom DataSource in Spring Boot's configuration
class?
- A. `@Bean public DataSource dataSource() { }`
- B. `@DataSource public DataSource dataSource() { }`
- C. `@CustomDataSource public DataSource dataSource() { }`
- D. `@DbSource public DataSource dataSource() { }`
- **Answer: A. `@Bean public DataSource dataSource() { }`**
32. Which annotation is used to enable cross-origin resource sharing (CORS) in a Spring Boot
application?
- A. `@EnableCORS`
- B. `@CrossOrigin`
- C. `@AllowOrigin`
- D. `@CorsSupport`
- **Answer: B. `@CrossOrigin`**
33. What is the correct syntax for defining a custom aspect in Spring Boot's configuration class?
- A. `@Aspect public class MyAspect { }`
- B. `@CustomAspect public class MyAspect {
}`
- C. `@Component public class MyAspect { }`
- D. `@AspectJ public class MyAspect { }`
- **Answer: A. `@Aspect public class MyAspect { }`**
34. Which annotation is used to enable distributed tracing in a Spring Boot application?
- A. `@EnableDistributedTracing`
- B. `@EnableTracing`
- C. `@EnableZipkin`
- D. `@EnableSleuth`
- **Answer: D. `@EnableSleuth`**
35. What is the correct syntax for defining a custom Validator in Spring Boot's configuration
class?
- A. `@Bean public MyValidator validator() { }`
- B. `@Validator public MyValidator validator() { }`
- C. `@CustomValidator public MyValidator validator() { }`
- D. `@Validation public MyValidator validator() { }`
- **Answer: A. `@Bean public MyValidator validator() { }`**
36. Which annotation is used to enable HATEOAS support in a Spring Boot application?
- A. `@EnableHateoas`
- B. `@EnableHypermedia`
- C. `@EnableRestSupport`
- D. `@EnableLinkSupport`
- **Answer: A. `@EnableHateoas`**
37. What is the correct syntax for defining a custom event listener in Spring Boot's configuration
class?
- A. `@EventListener public class MyEventListener { }`
- B. `@Listener public class MyEventListener { }`
- C. `@EventSupport public class MyEventListener { }`
- D. `@CustomListener public class MyEventListener { }`
- **Answer: A. `@EventListener public class MyEventListener { }`**
38. Which annotation is used to enable JMS listener container factory in a Spring Boot
application?
- A. `@EnableJms`
- B. `@EnableJmsListeners`
- C. `@EnableJmsContainer`
- D. `@EnableJmsConfiguration`
- **Answer: A. `@EnableJms`**
39. What is the correct syntax for defining a custom message source in Spring Boot's
configuration class?
- A. `@Bean public MessageSource messageSource() { }`
- B. `@MessageSource public MessageSource messageSource() { }`
- C. `@CustomMessageSource public MessageSource messageSource() { }`
- D. `@Source public MessageSource messageSource() { }`
- **Answer: A. `@Bean public MessageSource messageSource() { }`**
40. Which annotation is used to enable Spring Boot's security features in a Spring Boot
application?
- A. `@EnableSecurity`
- B. `@EnableWebSecurity`
- C. `@EnableSecure`
- D. `@EnableAuthentication`
- **Answer: B. `@EnableWebSecurity`*