Spring Framework MCQs

  1. Which of the following is true about Spring Framework?
    a) Provides comprehensive infrastructure support for Java apps
    b) Core features include IoC and DI
    c) Supports modular architecture
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  2. What will be printed?
    1 import org.springframework.context.*;
    2 import org.springframework.context.support.ClassPathXmlApplicationContext;
    3 class EduinqService {
    4 public void serve(){ System.out.println("Eduinq Service Running"); }
    5 }
    6 public class Test {
    7 public static void main(String[] args) {
    8 ApplicationContext ctx = new ClassPathXmlApplicationContext("eduinq.xml");
    9 EduinqService s = (EduinqService) ctx.getBean("eduinqService");
    10 s.serve();
    11 }
    12 }
    a) Eduinq Service Running
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Service Running

  3. Which of the following is true about IoC (Inversion of Control)?
    a) Objects are managed by container
    b) Promotes loose coupling
    c) Achieved via Dependency Injection
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  4. Which of the following is true about Dependency Injection types?
    a) Constructor Injection
    b) Setter Injection
    c) Field Injection
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  5. What will be printed?
    1 import org.springframework.beans.factory.annotation.*;
    2 import org.springframework.stereotype.*;
    3 @Component
    4 class EduinqService {
    5 public String getMsg(){ return "Eduinq DI"; }
    6 }
    7 @Component
    8 class Client {
    9 @Autowired EduinqService service;
    10 public void work(){ System.out.println(service.getMsg()); }
    11 }
    a) Eduinq DI
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq DI

  6. Which of the following is true about Bean lifecycle methods?
    a) init() called after properties set
    b) destroy() called on shutdown
    c) Custom methods can be configured
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  7. What will be printed?
    1 import javax.annotation.*;
    2 class EduinqBean {
    3 @PostConstruct
    4 public void init(){ System.out.println("Eduinq Init"); }
    5 @PreDestroy
    6 public void destroy(){ System.out.println("Eduinq Destroy"); }
    7 }
    a) Eduinq Init then Eduinq Destroy
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Init then Eduinq Destroy

  8. Which of the following is true about Bean scopes in Spring?
    a) Singleton
    b) Prototype
    c) Request, Session, Application (web)
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  9. Which of the following is true about ApplicationContext vs BeanFactory?
    a) ApplicationContext is advanced container
    b) BeanFactory is basic container
    c) ApplicationContext supports AOP, events, internationalization
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  10. Which of the following is true about Spring AOP?
    a) Aspect Oriented Programming
    b) Provides cross cutting concerns like logging, security
    c) Uses proxies internally
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  11. What will be printed?
    1 import org.aspectj.lang.annotation.*;
    2 @Aspect
    3 class EduinqAspect {
    4 @Before("execution(* EduinqService.serve(..))")
    5 public void log(){ System.out.println("Eduinq Before Advice"); }
    6 }
    7 class EduinqService {
    8 public void serve(){ System.out.println("Eduinq Service"); }
    9 }
    a) Eduinq Before Advice then Eduinq Service
    b) Eduinq Service then Eduinq Before Advice
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Before Advice then Eduinq Service

  12. Which of the following is true about @Component annotation?
    a) Marks class as Spring bean
    b) Detected during component scanning
    c) Equivalent to XML bean definition
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  13. Which of the following is true about @Configuration annotation?
    a) Marks class as source of bean definitions
    b) Used with @Bean methods
    c) Replaces XML configuration
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  14. Which of the following is true about @Bean annotation?
    a) Defines bean in @Configuration class
    b) Method return object registered as bean
    c) Supports custom initialization
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  15. What will be printed?
    1 import org.springframework.context.annotation.*;
    2 @Configuration
    3 class EduinqConfig {
    4 @Bean
    5 public String eduinqBean(){ return "Eduinq Bean"; }
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(EduinqConfig.class);
    10 System.out.println(ctx.getBean("eduinqBean"));
    11 }
    12 }
    a) Eduinq Bean
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Bean

  16. Which of the following is true about @Qualifier annotation?
    a) Resolves ambiguity between multiple beans
    b) Works with @Autowired
    c) Specifies bean name explicitly
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  17. What will be printed?
    1 import org.springframework.beans.factory.annotation.*;
    2 import org.springframework.stereotype.*;
    3 interface EduinqService { String getMsg(); }
    4 @Component("serviceA")
    5 class ServiceA implements EduinqService { public String getMsg(){ return "Eduinq A"; } }
    6 @Component("serviceB")
    7 class ServiceB implements EduinqService { public String getMsg(){ return "Eduinq B"; } }
    8 @Component
    9 class Client {
    10 @Autowired @Qualifier("serviceB") EduinqService service;
    11 public void work(){ System.out.println(service.getMsg()); }
    12 }
    a) Eduinq B
    b) Eduinq A
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq B

  18. Which of the following is true about Spring Profiles?
    a) Allow grouping of beans by environment
    b) Activated via @Profile annotation
    c) Controlled by spring.profiles.active property
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  19. Which of the following is true about BeanPostProcessor?
    a) Intercepts bean initialization
    b) Provides postProcessBeforeInitialization() and postProcessAfterInitialization()
    c) Used for custom modifications
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  20. What will be printed?
    1 import org.springframework.beans.factory.config.*;
    2 class EduinqProcessor implements BeanPostProcessor {
    3 public Object postProcessBeforeInitialization(Object bean, String name) {
    4 System.out.println("Eduinq Before Init: " + name);
    5 return bean;
    6 }
    7 }
    a) Eduinq Before Init: beanName
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Before Init: beanName

  21. Which of the following is true about AOP advice types?
    a) Before advice runs before method
    b) After advice runs after method
    c) Around advice surrounds method execution
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  22. Which of the following is true about Pointcut expressions?
    a) Define join points
    b) Use AspectJ syntax
    c) Can match methods, classes, packages
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  23. What will be printed?
    1 import org.aspectj.lang.annotation.*;
    2 @Aspect
    3 class EduinqAspect {
    4 @After("execution(* EduinqService.serve(..))")
    5 public void afterAdvice(){ System.out.println("Eduinq After Advice"); }
    6 }
    7 class EduinqService {
    8 public void serve(){ System.out.println("Eduinq Service"); }
    9 }
    a) Eduinq Service then Eduinq After Advice
    b) Eduinq After Advice then Eduinq Service
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Service then Eduinq After Advice

  24. Which of the following is true about Around advice?
    a) Controls method execution
    b) Can modify arguments and return values
    c) Provides ProceedingJoinPoint
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  25. Which of the following is true about Spring Transaction Management?
    a) Declarative with @Transactional
    b) Programmatic via TransactionTemplate
    c) Supports rollback rules
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  26. What will be printed?
    1 import org.springframework.transaction.annotation.*;
    2 class EduinqService {
    3 @Transactional
    4 public void save(){ System.out.println("Eduinq Transactional Save"); }
    5 }
    a) Eduinq Transactional Save
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Transactional Save

  27. Which of the following is true about @EnableAspectJAutoProxy?
    a) Enables AOP proxy support
    b) Used in @Configuration classes
    c) Allows @Aspect beans to work
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  28. Which of the following is true about Spring Events?
    a) ApplicationEvent published via ApplicationEventPublisher
    b) Listeners handle events
    c) Useful for decoupled communication
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  29. Which of the following is true about @Lazy annotation?
    a) Delays bean initialization
    b) Useful for heavy beans
    c) Can be applied to @Bean methods
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  30. Which of the following is true about @Primary annotation?
    a) Marks bean as default choice
    b) Resolves ambiguity with multiple beans
    c) Works with @Autowired
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  31. Which of the following is true about Spring Expression Language (SpEL)?
    a) Provides powerful expression evaluation
    b) Syntax like #{expression}
    c) Supports property access, method invocation
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  32. Which of the following is true about Spring BeanFactoryPostProcessor?
    a) Modifies bean definitions before instantiation
    b) Provides postProcessBeanFactory()
    c) Useful for property placeholder config
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  33. Which of the following is true about @Scope annotation?
    a) Defines bean scope
    b) Values include singleton, prototype, request, session
    c) Works with @Component
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  34. Which of the following is true about Spring Boot vs Spring Framework?
    a) Spring Boot simplifies configuration
    b) Provides auto configuration
    c) Embedded servers like Tomcat
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  35. Which of the following is true about @Value annotation?
    a) Injects values into fields
    b) Supports property placeholders
    c) Can inject literals
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  36. Which of the following is true about @PropertySource annotation?
    a) Loads properties file
    b) Used in @Configuration classes
    c) Supports multiple files
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  37. Which of the following is true about Spring AOP proxies?
    a) JDK dynamic proxies for interfaces
    b) CGLIB proxies for classes
    c) Created automatically by container
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  38. Which of the following is true about @Order annotation?
    a) Defines order of execution
    b) Used with aspects, filters, interceptors
    c) Lower value means higher priority
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  39. Which of the following is true about Spring Bean validation?
    a) Uses JSR 380 (Bean Validation API)
    b) Annotations like @NotNull, @Size
    c) Integrated with Spring MVC
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  40. Which of the following is true about @RestController annotation?
    a) Combines @Controller and @ResponseBody
    b) Simplifies REST API creation
    c) Returns JSON/XML directly
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  41. Which of the following is true about Spring MVC DispatcherServlet?
    a) Front controller in MVC
    b) Routes requests to controllers
    c) Configured in web.xml or auto configured
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  42. Which of the following is true about @Transactional propagation types?
    a) REQUIRED, REQUIRES_NEW, SUPPORTS
    b) Define transaction behavior
    c) Control nested transactions
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  43. Which of the following is true about Spring caching?
    a) @Cacheable caches method results
    b) @CacheEvict removes cache entries
    c) Supports multiple cache providers
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  44. Which of the following is true about Spring Scheduling?
    a) @Scheduled defines scheduled tasks
    b) Supports cron expressions
    c) Requires @EnableScheduling
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  45. What will be printed?
    1 import org.springframework.scheduling.annotation.*;
    2 import org.springframework.stereotype.*;
    3 @EnableScheduling
    4 @Component
    5 class EduinqScheduler {
    6 @Scheduled(fixedRate = 1000)
    7 public void task(){ System.out.println("Eduinq Scheduled Task"); }
    8 }
    a) Eduinq Scheduled Task (every second)
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Scheduled Task (every second)

  46. Which of the following is true about Spring Boot auto configuration?
    a) Provides default configurations
    b) Reduces boilerplate setup
    c) Controlled via @EnableAutoConfiguration
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  47. Which of the following is true about Spring BeanFactory vs ApplicationContext?
    a) BeanFactory is basic container
    b) ApplicationContext adds enterprise features
    c) ApplicationContext supports events and AOP
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  48. Which of the following is true about Spring AOP join points?
    a) Represent points in execution
    b) Include method calls, executions
    c) Defined by pointcuts
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  49. Which of the following is true about Spring Boot starters?
    a) Provide pre configured dependencies
    b) Simplify project setup
    c) Examples include spring boot starter web, spring boot starter data jpa
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  50. Which of the following is true about Spring AOP best practices?
    a) Use AOP for cross cutting concerns only
    b) Avoid overuse to reduce complexity
    c) Prefer declarative configuration
    d) All of the above
    View Answer

    Correct answer: D — All of the above

Quick Links to Explore