Spring Boot Quiz - MCQ - Multiple Choice Questions
Q. For the following spring boot code
@SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/mydb"); dataSource.setUsername("root"); dataSource.setPassword("password"); return dataSource; } @Bean public JdbcTemplate jdbcTemplate(DataSource dataSource) { return new JdbcTemplate(dataSource); } @Autowired private JdbcTemplate jdbcTemplate; // Rest of the application code... }A. The `dataSource` bean will be automatically picked up by Spring Boot and configured as the application's primary `DataSource`.
B. The `jdbcTemplate` bean will be automatically created by Spring Boot using the `dataSource` bean defined in the `dataSource()` method
C. The `dataSource` bean will be created but won't be used by Spring Boot unless explicitly injected into a component.
D. The application will fail to start because there is no `@RestController` or `@Controller` class defined in the code snippet.
Q. What is Spring Initializer primarily used for?
A. Generating boilerplate code for Spring Boot applicationsB. Running Spring Boot applications
C. Debugging Spring Boot applications
D. Deploying Spring Boot applications
Q. Which of the following is true about Spring Security?
A. Spring Security is a framework that provides authentication and authorization support for Spring-based applicationsB. Spring Security is only applicable for securing web applications and does not support other types of applications
C. Spring Security is a stand-alone framework and cannot be integrated with other Spring modules
D. Spring Security does not provide any out-of-the-box support for implementing multi-factor authentication
Q. Which of the following statements is true about Spring AOP (Aspect-Oriented Programming)?
A. Spring AOP is used for handling exceptions in Spring applicationsB. Spring AOP can only be used with Spring MVC applications
C. Spring AOP is primarily used for database access and transaction management
D. Spring AOP allows cross-cutting concerns to be separated from the business logic
Q. Which of the following statements is true about Spring Database integration?
A. Spring provides a built-in database management system for relational databasesB. Spring only supports integration with SQL Server and Oracle databases
C. Spring provides support for accessing and interacting with databases through JDBC and Object-Relational Mapping (ORM) frameworks
D. Spring Database integration is limited to NoSQL databases only
Q. Which of the following is true about Spring Boot?
A. Spring Boot is a separate framework and not a part of the Spring ecosystemB. Spring Boot requires manual configuration for every aspect of the application
C. Spring Boot simplifies the development of Spring applications by providing an opinionated approach and auto-configuration
D. Spring Boot is only suitable for small-scale applications with limited functionality
Q. Which of the following Spring Boot annotations is used to indicate the main class of a Spring Boot application?
A. @ComponentB. @Service
C. @RestController
D. @SpringBootApplication
Q. Which of the following statements is true about the @Autowired annotation in Spring Boot?
A. @Autowired is used to inject dependencies into Spring Boot applicationsB. @Autowired is only applicable for injecting dependencies of type String
C. @Autowired is optional and not required for dependency injection in Spring Boot
D. @Autowired is mandatory in Spring Boot and can only be used in service classes
Q. Which of the following code snippets demonstrates the correct configuration of a Spring Boot REST Controller?
A.@RestController public class MyController { @GetMapping("/hello") public String hello() { return "Hello, World!"; } }B.
@Controller @RequestMapping("/api") public class MyController { @GetMapping("/hello") public String hello() { return "Hello, World!"; } }C.
@RestController @RequestMapping("/api") public class MyController { @RequestMapping("/hello") public String hello() { return "Hello, World!"; } }D.
@Controller public class MyController { @RequestMapping(value = "/hello", method = RequestMethod.GET) @ResponseBody public String hello() { return "Hello, World!"; } }