Core Spring Boot Test 3

    Question 1CORE SPRING BOOT - Binding Properties to POJO

    Which annotation allows binding properties from application.properties or application.yml to a Java POJO?

    Question 2CORE SPRING BOOT - Key Features

    Which of the following is NOT a key feature of Spring Boot?

    Question 3CORE SPRING BOOT - @Controller vs @RestController

    Which statement correctly distinguishes between @Controller and @RestController?

    Question 4CORE SPRING BOOT - Query Parameters with @RequestParam

    Which annotation is used to extract query parameters in a Spring Boot controller?

    Question 5CORE SPRING BOOT - Constructor Injection Example

    What will happen when this Spring Boot code runs?

    @Component public class ServiceA {} @Component public class ServiceB { private final ServiceA serviceA; @Autowired public ServiceB(ServiceA serviceA) { this.serviceA = serviceA; } }

    Question 6CORE SPRING BOOT - Code Snippet (@Profile)

    What will happen when this code runs with the "dev" profile active?

    @Component @Profile("dev") public class DevDatabaseConfig implements DatabaseConfig {}

    Question 7CORE SPRING BOOT - Code Snippet (Custom Health Indicator)

    What will the following code do in a Spring Boot application?

    @Component public class CustomHealthIndicator implements HealthIndicator { @Override public Health health() { return Health.up().withDetail("customCheck", "All good!").build(); } }

    Question 8CORE SPRING BOOT - Code Snippet (Multiple Exceptions)

    What does the following code achieve?

    @ControllerAdvice public class GlobalHandler { @ExceptionHandler({IOException.class, SQLException.class}) public ResponseEntity<String> handleIOAndSQL(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("Error: " + ex.getMessage()); } }

    Question 9CORE SPRING BOOT - Configuring Logging in application.properties

    How can you set the logging level for a specific package in Spring Boot using application.properties?

    Question 10CORE SPRING BOOT - Code Snippet (Custom Port)

    What port will the embedded Tomcat server run on with the following configuration?

    server: port: 9090

    Question 11CORE SPRING BOOT - Using @Value Annotation

    What is the purpose of the @Value annotation in Spring Boot configuration?

    Question 12CORE SPRING BOOT - spring-boot-starter-web Dependency

    When you add the spring-boot-starter-web dependency to your project, what does Spring Boot auto-configure for you by default?

    Question 13CORE SPRING BOOT - Code Snippet (@ConfigurationProperties)

    What is the purpose of the following code?

    @ConfigurationProperties(prefix = "app") @Component public class AppProperties { private String name; private int version; // getters and setters }

    Question 14CORE SPRING BOOT - Code Snippet (@RequestParam)

    What will `/api/user?id=10` return in the following code?

    @RestController @RequestMapping("/api") public class UserController { @GetMapping("/user") public String getUser(@RequestParam int id) { return "User ID: " + id; } }

    Question 15CORE SPRING BOOT - Setter Injection Example

    In the following code, how is ServiceA injected into ServiceB?

    @Component public class ServiceA {} @Component public class ServiceB { private ServiceA serviceA; @Autowired public void setServiceA(ServiceA serviceA) { this.serviceA = serviceA; } }

    Question 16CORE SPRING BOOT - Multiple Profiles in a Bean

    How can you make a bean active for multiple profiles?

    Question 17CORE SPRING BOOT - Code Snippet (Custom Metrics)

    What does the following code achieve?

    @Component public class CustomMetrics { @Autowired private MeterRegistry registry; public void incrementRequests() { registry.counter("custom.requests").increment(); } }

    Question 18CORE SPRING BOOT - ResponseEntity in Exception Handling

    Why is ResponseEntity commonly used in exception handlers?

    Question 19CORE SPRING BOOT - Code Snippet (Logging in a Spring Component)

    What will happen when this component is executed?

    @Component public class MyService { private static final Logger logger = LoggerFactory.getLogger(MyService.class); public void process() { logger.info("Processing started"); } }

    Question 20CORE SPRING BOOT - Code Snippet (Embedded Server Selection)

    Which server will Spring Boot use when this dependency is included?

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>