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 applications.B. 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 provides authentication and authorization support for Spring-based applications.B. Spring Security is only applicable to web applications.
C. Spring Security cannot be integrated with other Spring modules.
D. Spring Security has no 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 only used for exception handling in Spring applications.B. 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 relational database management system.B. Spring only supports SQL Server and Oracle integration.
C. Spring supports database access through JDBC and ORM frameworks.
D. Spring database integration is limited to NoSQL stores.
Q. Which of the following is true about Spring Boot?
A. Spring Boot is a completely separate framework, unrelated to Spring.B. Spring Boot requires manual configuration for everything.
C. Spring Boot speeds development with opinionated defaults and auto-configuration.
D. Spring Boot only fits very small applications.
Q. Which Spring Boot annotation marks the main application class?
A. @ComponentB. @Service
C. @RestController
D. @SpringBootApplication
Q. Which statement about the @Autowired annotation in Spring Boot is true?
A. @Autowired injects Spring-managed dependencies into application components.B. @Autowired only works for String dependencies.
C. @Autowired is optional and never needed for dependency injection.
D. @Autowired is mandatory and limited to service classes.
Q. Which code snippet shows the correct Spring Boot REST Controller configuration?
A. Uses `@RestController` with `@GetMapping` to expose `/hello`.
@RestController
public class MyController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
B. Uses `@Controller` with `@RequestMapping` at the class level only.
@Controller
@RequestMapping("/api")
public class MyController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
C. Combines `@RestController` and `@RequestMapping`, but not HTTP method-specific mappings.
@RestController
@RequestMapping("/api")
public class MyController {
@RequestMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
D. Uses `@Controller` plus `@ResponseBody` at the method level.
@Controller
public class MyController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
@ResponseBody
public String hello() {
return "Hello, World!";
}
}