Core Spring Boot Test 4

    Question 1CORE SPRING BOOT - Nested YAML Configuration

    How do you define nested properties in a YAML configuration file?

    Question 2CORE SPRING BOOT - Bean Scope

    What is the default scope of a bean in a Spring Boot application?

    Question 3CORE SPRING BOOT - @Service and @Repository

    Which of the following is true regarding @Service and @Repository annotations?

    Question 4CORE SPRING BOOT - Default Values with @RequestParam

    How can you set a default value for a query parameter?

    Question 5CORE SPRING BOOT - Field Injection Example

    Identify the injection type in the following code:

    @Component public class ServiceA {} @Component public class ServiceB { @Autowired private ServiceA serviceA; }

    Question 6CORE SPRING BOOT - Code Snippet (Profile-Specific Property)

    Which value will be injected into port when the "prod" profile is active?

    server: port: 8080 --- spring: profiles: prod server: port: 9090 @Value("${server.port}") private int port;

    Question 7CORE SPRING BOOT - Management Port

    How can you expose Actuator endpoints on a separate port than the application itself?

    Question 8CORE SPRING BOOT - Code Snippet (@RestControllerAdvice)

    What is the effect of using @RestControllerAdvice instead of @ControllerAdvice?

    @RestControllerAdvice public class GlobalRestHandler { @ExceptionHandler(IllegalArgumentException.class) public Map<String, String> handleIllegalArgs(IllegalArgumentException ex) { Map<String, String> map = new HashMap<>(); map.put("error", ex.getMessage()); return map; } }

    Question 9CORE SPRING BOOT - Code Snippet (Custom Logback Configuration)

    Consider the following logback-spring.xml snippet. What does it do?

    <logger name="com.example" level="DEBUG"/> <root level="INFO"> <appender-ref ref="CONSOLE"/> </root>

    Question 10CORE SPRING BOOT - Code Snippet (Context Path)

    What is the base URL for the application with the following configuration?

    server: port: 8081 servlet: context-path: /api

    Question 11CORE SPRING BOOT - Environment Variables Override

    In Spring Boot, which of the following has the highest precedence when determining a configuration value?

    Question 12CORE SPRING BOOT - Microservices Support

    How does Spring Boot's architecture promote the development of microservices?

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

    What does the following code do?

    @Bean @ConditionalOnMissingBean public MyService myService() { return new MyService(); }

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

    Which HTTP method does the following handler respond to?

    @RestController @RequestMapping("/api") public class ProductController { @PostMapping("/product") public String addProduct(@RequestBody String name) { return "Added product: " + name; } }

    Question 15CORE SPRING BOOT - Benefits of Constructor Injection

    Which of the following is a key advantage of constructor injection over setter or field injection?

    Question 16CORE SPRING BOOT - Default Profile

    What is the default profile in Spring Boot if no profile is explicitly activated?

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

    What will this code create in a Spring Boot application?

    @Component @Endpoint(id = "custom") public class CustomEndpoint { @ReadOperation public String info() { return "Custom Endpoint Info"; } }

    Question 18CORE SPRING BOOT - Code Snippet (Default Exception Handling)

    What will happen if an unhandled exception occurs in a Spring Boot controller and no @ControllerAdvice is defined?

    @RestController public class SampleController { @GetMapping("/test") public String test() { throw new RuntimeException("Something went wrong!"); } }

    Question 19CORE SPRING BOOT - Logging in YAML

    How do you configure logging levels in application.yml?

    Question 20CORE SPRING BOOT - Embedded Server Threads

    Which of the following is true regarding embedded server thread configuration in Spring Boot?