























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























































































Question 1. Which annotation combines @Configuration, @EnableAutoConfiguration, and @ComponentScan in a Spring Boot application? A) @SpringBootConfiguration B) @SpringBootApplication C) @EnableAutoConfiguration D) @ComponentScan Answer: B Explanation: @SpringBootApplication is a meta‑annotation that includes @Configuration, @EnableAutoConfiguration, and @ComponentScan, simplifying bootstrapping. Question 2. In Spring IoC, what is the primary difference between BeanFactory and ApplicationContext? A) BeanFactory supports AOP, ApplicationContext does not B) ApplicationContext provides internationalization, event propagation, and higher‑level services C) BeanFactory eagerly creates beans, ApplicationContext lazily creates them D) ApplicationContext cannot load XML configuration Answer: B Explanation: ApplicationContext extends BeanFactory and adds features such as message resolution, event publication, and application‑level services. Question 3. Which of the following is a valid way to inject a dependency using field injection? A) @Autowired private Service service; B) public Service(Service service) { this.service = service; } C) public void setService(Service service) { this.service = service; }
D) @Inject private Service service; Answer: A Explanation: Field injection uses @Autowired (or @Inject) directly on a field. Option D is also valid with JSR‑330, but the question asks specifically for Spring’s @Autowired. Question 4. When multiple beans of the same type exist, how can you specify which bean should be injected? A) Use @Primary on the desired bean B) Use @Qualifier with the bean name C) Both A and B are correct D) Use @Autowired(required=false) Answer: C Explanation: @Primary marks a bean as the default, while @Qualifier explicitly selects a bean by name; both resolve ambiguity. Question 5. Which bean scope creates a new instance each time it is requested from the container? A) singleton B) prototype C) request D) session Answer: B Explanation: Prototype scope returns a fresh bean instance on every retrieval, unlike singleton which returns the same instance.
D) Marks a bean as primary Answer: B Explanation: @Value resolves the placeholder using Spring’s property resolution mechanism, injecting the actual port value. Question 9. Which Spring Expression Language (SpEL) expression retrieves the length of a string property name? A) #{name.length()} B) ${name.length()} C) #{T(String).length(name)} D) ${T(String).length(name)} Answer: A Explanation: SpEL uses #{…} syntax; name.length() invokes the length method on the property. Question 10. How can a Spring profile be activated via command‑line argument? A) --spring.profiles.active=dev B) - Dspring.profile=dev C) --profile=dev D) - Dspring.profiles=dev Answer: A Explanation: The --spring.profiles.active argument sets the active profile(s) at startup. Question 11. In AOP, which type of advice runs before the matched method execution? A) @AfterReturning
B) @Before C) @Around D) @AfterThrowing Answer: B Explanation: @Before advice executes prior to the join point method. Question 12. Which proxying mechanism is used when the target class does not implement any interfaces? A) JDK Dynamic Proxy B) CGLIB proxy C) Java Reflection Proxy D) AspectJ compile‑time weaving Answer: B Explanation: CGLIB creates a subclass proxy, used when there are no interfaces for JDK dynamic proxies. Question 13. What is the purpose of a Spring Boot starter dependency? A) To provide a complete application server B) To aggregate commonly used libraries and auto‑configure them C) To replace Maven or Gradle D) To enforce a specific logging framework Answer: B Explanation: Starters bundle related dependencies and trigger appropriate auto‑configuration.
Answer: B Explanation: @EnableAutoConfiguration (or @SpringBootApplication, which includes it) accepts an exclude attribute to prevent particular auto‑configurations. Question 17. What command runs a Spring Boot application packaged as an executable JAR? A) java - jar myapp.jar B) mvn spring-boot:run C) gradle bootRun D) spring run myapp.jar Answer: A Explanation: Executable JARs are launched with java - jar. Question 18. Which embedded servlet container is the default for Spring Boot 2.x? A) Jetty B) Undertow C) Tomcat D) Netty Answer: C Explanation: Tomcat is the default embedded container unless overridden. Question 19. What does Spring Boot DevTools primarily provide? A) Production‑grade logging B) Automatic restart and live reload during development
C) Advanced security features D) Database migration support Answer: B Explanation: DevTools watches classpath changes and restarts the application automatically. Question 20. In Spring Data JPA, which method name will generate a query to find users by email ignoring case? A) findByEmailIgnoreCase(String email) B) findByEmail(String email) C) readByEmailIgnoreCase(String email) D) getByEmailIgnoreCase(String email) Answer: A Explanation: The “IgnoreCase” suffix instructs Spring Data to add case‑insensitive comparison. Question 21. Which annotation marks a class as a JPA entity? A) @Table B) @Entity C) @Component D) @Repository Answer: B Explanation: @Entity designates a POJO as a persistent JPA entity. Question 22. How can you define a native SQL query in a Spring Data repository method?
Explanation: REQUIRES_NEW starts a fresh transaction, suspending any current transaction. Question 25. Which isolation level prevents dirty reads? A) READ_UNCOMMITTED B) READ_COMMITTED C) REPEATABLE_READ D) SERIALIZABLE Answer: B Explanation: READ_COMMITTED ensures that a transaction only reads data that has been committed. Question 26. In Spring MVC, which annotation indicates that a method returns the response body directly? A) @ResponseBody B) @RestController C) @Controller D) Both A and B Answer: D Explanation: @ResponseBody on a method or @RestController on the class (which itself includes @ResponseBody) both cause direct body rendering. Question 27. Which HTTP method is conventionally used to partially update a resource? A) POST B) PUT C) PATCH
Answer: C Explanation: PATCH applies partial modifications, whereas PUT replaces the entire resource. Question 28. How do you bind a URI template variable to a method parameter? A) @PathVariable("id") Long id B) @RequestParam("id") Long id C) @RequestBody Long id D) @ModelAttribute Long id Answer: A Explanation: @PathVariable extracts values from the URI path. Question 29. What is the purpose of @ControllerAdvice? A) To define a global exception handler and model attributes B) To advise the compiler about controller classes C) To replace @RestController D) To configure view resolvers Answer: A Explanation: @ControllerAdvice allows centralized exception handling and binding of model attributes across controllers. Question 30. Which class is recommended for making non‑blocking HTTP calls in a Spring WebFlux application? A) RestTemplate
Question 33. What does the hasRole('ADMIN') expression check in a Spring Security configuration? A) That the user has a GrantedAuthority named "ROLE_ADMIN" B) That the user’s username is ADMIN C) That the user’s password contains ADMIN D) That the user is authenticated Answer: A Explanation: Spring Security prefixes roles with "ROLE_"; hasRole('ADMIN') checks for the authority "ROLE_ADMIN". Question 34. Which component is responsible for generating and validating JWT tokens in a typical Spring Boot security setup? A) JwtAuthenticationFilter B) BCryptPasswordEncoder C) DaoAuthenticationProvider D) OAuth2AuthorizationServer Answer: A Explanation: A custom filter (often extending OncePerRequestFilter) handles JWT extraction, validation, and authentication. Question 35. Which Actuator endpoint provides information about the current memory usage? A) /actuator/health B) /actuator/info C) /actuator/metrics/jvm.memory.used
D) /actuator/beans Answer: C Explanation: Metrics endpoints expose JVM metrics; /actuator/metrics/jvm.memory.used reports memory usage. Question 36. How can you expose a custom health indicator named “database”? A) Implement HealthIndicator and annotate with @Component("databaseHealthIndicator") B) Add a bean of type HealthIndicator named “databaseHealthIndicator” C) Create a class extending AbstractHealthIndicator and register as a bean named “databaseHealthIndicator” D) All of the above Answer: D Explanation: Any of these approaches registers a custom health indicator that appears as db (or the bean name) under /actuator/health. Question 37. Which dependency is required to use Micrometer core metrics in a Spring Boot application? A) micrometer-core B) spring-boot-starter-actuator C) spring-boot-starter-metrics D) spring-boot-starter-micrometer Answer: B (spring-boot-starter-actuator pulls in micrometer) Explanation: The Actuator starter includes Micrometer and registers default metrics.
Explanation: @SpringBootTest loads the complete Spring Boot context, useful for integration testing. Question 41. Which annotation is used to test only JPA repositories without loading the full context? A) @DataJpaTest B) @JpaTest C) @RepositoryTest D) @SpringBootTest Answer: A Explanation: @DataJpaTest configures an in‑memory database and scans only repository beans. Question 42. How can you test a Spring MVC controller without starting a server? A) Using MockMvc with @WebMvcTest B) Using RestTemplate C) Using TestRestTemplate D) Using WebTestClient Answer: A Explanation: MockMvc combined with @WebMvcTest loads the MVC layer and allows request simulation. Question 43. Which starter provides support for consuming messages from Apache Kafka? A) spring-boot-starter-kafka B) spring-boot-starter-messaging C) spring-boot-starter-stream-kafka
D) spring-boot-starter-activemq Answer: A Explanation: spring-boot-starter-kafka brings in Spring for Apache Kafka. Question 44. In a microservice architecture, which component typically provides client‑side load balancing for REST calls? A) Eureka Server B) Ribbon (or Spring Cloud LoadBalancer) C) Zuul Gateway D) Consul Answer: B Explanation: Ribbon (or the newer Spring Cloud LoadBalancer) performs client‑side load balancing. Question 45. Which Dockerfile instruction copies the built JAR into the container image? A) COPY target/.jar app.jar B) ADD target/.jar /app.jar C) RUN cp target/*.jar /app.jar D) EXPOSE app.jar Answer: A Explanation: COPY is the standard instruction to copy files from the build context into the image. Question 46. Which Spring Boot property changes the embedded server’s port to 8085?
Answer: A Explanation: The spring.autoconfigure.exclude property takes fully qualified class names to exclude. Question 49. Which annotation marks a method that should be executed after the bean is fully initialized and all proxies are created? A) @PostConstruct B) @PreDestroy C) @Bean(initMethod=…) D) @EventListener(ApplicationReadyEvent.class) Answer: D Explanation: ApplicationReadyEvent fires after the context is refreshed and all beans are fully initialized, including proxies. Question 50. What does the @EnableConfigurationProperties annotation do? A) Registers @ConfigurationProperties beans for binding external properties B) Enables component scanning C) Activates Spring MVC D) Turns on AOP auto‑proxying Answer: A Explanation: It tells Spring to bind @ConfigurationProperties classes to the environment. Question 51. Which of the following is NOT a valid way to define a Spring bean using Java configuration? A) @Bean public Service myService() { return new ServiceImpl(); }
B) @Component public Service myService() { return new ServiceImpl(); } C) @Bean public Service myService() { return new ServiceImpl(); } D) @Configuration public class Config { … } Answer: B Explanation: @Component is used on classes, not on @Bean methods; the method should be annotated with @Bean. Question 52. In Spring Security, what is the default password encoder if none is explicitly configured? A) NoOpPasswordEncoder B) BCryptPasswordEncoder C) Pbkdf2PasswordEncoder D) DelegatingPasswordEncoder Answer: D Explanation: Since Spring Security 5, a DelegatingPasswordEncoder with a default BCrypt implementation is used. Question 53. Which annotation can be placed on a method to schedule its execution at a fixed rate? A) @Scheduled(fixedRate = 5000) B) @Async C) @EnableScheduling D) @Cron Answer: A (requires @EnableScheduling on a configuration class)