Spring MCQ (Multiple Choice Questions)

Here are 1000 MCQs on Spring (Chapterwise).

1. What is the Spring Framework?
a) A framework for building mobile applications
b) A library for creating desktop applications
c) A framework for building Java-based enterprise applications
d) A tool for writing JavaScript applications
View Answer

Answer: c
Explanation: The Spring Framework is a powerful framework for building Java-based enterprise applications, providing comprehensive infrastructure support.

2. How to inject a Spring bean into domain objects?
a) Java Based
b) AspectJ
c) XML
d) AOP
View Answer

Answer: d
Explanation: To inject a Spring bean into domain objects created outside Spring, you need the help of AOP.

3. Scripting languages supported by Spring?
a) All of the mentioned
b) BeanShell
c) JRuby
d) Groovy
View Answer

Answer: a
Explanation: Spring supports the three above-mentioned scripting languages.

4. Servlet filter registered in web deployment descriptor, which filters request in spring application context.
a) DelegatingFilterProxy
b) DelegatingProxy
c) DelegatingFilter
d) None of the mentioned
View Answer

Answer: a
Explanation: As servlet filters must be registered in the web deployment descriptor to take effect, you have to register a DelegatingFilterProxy instance in the web deployment descriptor, which is a servlet filter that delegates request filtering to a filter in Spring’s application context.

5. Which module of the Spring Framework is used for building web applications?
a) Spring Boot
b) Spring ORM
c) Spring AOP
d) Spring MVC
View Answer

Answer: d
Explanation: The Spring MVC module is specifically designed for building web applications following the Model-View-Controller (MVC) design pattern.
advertisement
advertisement

6. Which of the following property editors are registered by Spring?
a) CustomNumberEditor
b) CustomDateEditor
c) FileEditor
d) CustomNetEditor
View Answer

Answer: c
Explanation: ClassEditor, FileEditor, LocaleEditor, and URLEditor are pre-registered by Spring, so you don’t need to register them again.

7. Which of the following is a Spring project designed to simplify building microservices?
a) Spring Data
b) Spring Cloud
c) Spring MVC
d) Spring Boot
View Answer

Answer: b
Explanation: Spring Cloud is a project that provides tools for building cloud-native applications and simplifies the development of microservices.

8. How does an Introduction advice do this in Spring?
a) web proxy
b) dynamic proxy
c) implements org.springframework.net.bundle interface
d) none of the mentioned
View Answer

Answer: b
Explanation: Introduction works by adding an interface to the dynamic proxy.

9. Which method is used to gracefully shut down all the bean processes after closing the spring container?
a) destroy method
b) shutdownHook
c) none of the mentioned
d) all of the mentioned
View Answer

Answer: b
Explanation: ShutdownHook method gracefully shuts down each bean process before closing the container.

10. Spring Security algorithms to secure passwords.
a) MD5
b) SHA
c) None of the mentioned
d) All of the mentioned
View Answer

Answer: d
Explanation: Spring Security supports several algorithms for encoding passwords (including MD5 and SHA) and provides built-in password encoders for these algorithms.

11. Session scope attribute to display error message.
a) SPRING_SECURITY_LAST_ERROR
b) SPRING_SECURITY_FIRST_EXCEPTION
c) SPRING_SECURITY_LAST_EXCEPTION
d) SPRING_SECURITY_EXCEPTION
View Answer

Answer: c
Explanation: If an error has occurred, you will have to display the error message by accessing the session scope attribute SPRING_SECURITY_LAST_EXCEPTION, which stores the last exception for the current user.

12. What does Spring Boot provide to simplify application development?
a) A built-in web server
b) Starter dependencies
c) Automatic configuration
d) All of the mentioned
View Answer

Answer: d
Explanation: Spring Boot provides features such as built-in web servers, automatic configuration, and starter dependencies to simplify application development.

13. Which of the following annotations is used to indicate a controller in Spring MVC?
a) @Component
b) @Controller
c) @Service
d) @Repository
View Answer

Answer: b
Explanation: The @Controller annotation is used in Spring MVC to indicate that a class serves as a controller, handling web requests and responses.

14. Which of the following is a characteristic of Spring’s Bean Lifecycle?
a) Beans are created at runtime only
b) All beans are created as singletons
c) Beans can be configured to execute custom initialization methods
d) Beans are destroyed when the application shuts down only
View Answer

Answer: c
Explanation: Spring allows configuring custom initialization methods for beans, which can be executed during the bean lifecycle.
advertisement

15. Which Spring annotation is used to mark a class as a repository?
a) @Service
b) @Repository
c) @Component
d) @Controller
View Answer

Answer: b
Explanation: The @Repository annotation is used to indicate that a class is a Data Access Object (DAO) and is responsible for interacting with the database.

16. Integration of JSF with Spring Application Context.
a) SpringBeanFacesELResolver
b) DelegatingVariableResolver
c) ContextLoaderListener
d) All of the mentioned
View Answer

Answer: d
Explanation: Due to the similarity between Spring and JSF bean models, it’s very easy to integrate them by registering the Spring-provided JSF variable resolver DelegatingVariableResolver (for JSF 1.1) or the SpringBeanFacesELResolver (for JSF 1.2 and greater).

17. Class which assists Spring Web flow in handling forms.
a) FormHandler
b) Form
c) Form-Handler
d) FormAction
View Answer

Answer: d
Explanation: Spring Web Flow provides a FormAction class to assist you in handling forms.

18. To use JSF Validation components provided by Spring Faces.
a) Facelets
b) Spring Javascript
c) Faces
d) None of the mentioned
View Answer

Answer: a
Explanation: To use the JSF validation components provided by Spring Faces, you have to use Facelets to create your JSF views.

19. To publish a REST service with Spring.
a) accessing data from third-party REST services
b) publishing an application’s data as a REST service
c) none of the mentioned
d) all of the mentioned
View Answer

Answer: d
Explanation: One involves publishing an application’s data as a REST service, while the other involves accessing data from third-party REST services to be used in an application.
advertisement

20. The service, which will simply fetch all the items that are for auction and return the description.
a) EventSpring
b) SpringBlaze DS
c) SpringFlex
d) All of the mentioned
View Answer

Answer: b
Explanation: Use Spring BlazeDS to set up a simple service and demonstrate its invocation from the client—a simple auction application that we’ll build on in subsequent recipes.

21. How does the Spring JDBC framework know that state 23505 should be mapped to DuplicateKeyException?
a) error code
b) SQL state
c) all of the mentioned
d) none of the mentioned
View Answer

Answer: c
Explanation: The error code and SQL state are database-specific, meaning different database products may return different codes for the same kind of error.

22. Spring EJB Support Classes for Different Types of EJB:
a) AbstractMessageDrivenBean
b) AbstractStatelessSessionBean
c) AbstractStatefulSessionBean
d) All of the mentioned
View Answer

Answer: d
Explanation: Spring EJB Support Classes for Different Types of EJB
EJB Support Class | EJB Type
AbstractStatelessSessionBean | Stateless session bean
AbstractStatefulSessionBean | Stateful session bean
AbstractMessageDrivenBean | General message-driven bean that may not use JMS
AbstractJmsMessageDrivenBean | Message-driven bean that uses JMS.

23. Which annotation is used to define a Spring configuration class?
a) @Service
b) @Component
c) @Repository
d) @Configuration
View Answer

Answer: d
Explanation: The @Configuration annotation is used to indicate that a class can be used by the Spring IoC container as a source of bean definitions.

24. What is the purpose of Aspect-Oriented Programming (AOP) in Spring?
a) To separate cross-cutting concerns from business logic
b) To handle user input in web applications
c) To improve performance of the application
d) To manage database transactions
View Answer

Answer: a
Explanation: AOP in Spring is used to separate cross-cutting concerns (like logging and security) from business logic, enhancing modularity and maintainability.

25. Which of the following is NOT a feature provided by the Spring Framework?
a) Aspect-Oriented Programming
b) Automatic Memory Management
c) Dependency Injection
d) Simplified Data Access
View Answer

Answer: b
Explanation: Automatic Memory Management is a feature of Java’s Garbage Collection, not specifically provided by the Spring Framework.

26. Proxying Spring services with EJB3s, injecting custom resources configured in Spring, or even using Spring to isolate your EJBs from acquiring references to other distributed resources such as a REST endpoint or an RMI endpoint.
a) SpringBeanAutowiring
b) SpringBeanAutowiringInterceptor
c) SpringBeanInterceptor
d) SpringBean
View Answer

Answer: b
Explanation: To do this, use Spring’s SpringBeanAutowiringInterceptor class to provide configuration for the EJB.

27. Spring-WS provides various abstract endpoint classes for you to process the request.
a) org.springframework.*
b) org.springframework.ws.server.endpoint
c) org.springframework.ws.server
d) none of the mentioned
View Answer

Answer: b
Explanation: Spring-WS provides various abstract endpoint classes for you to process the request and response XML messages using different XML processing technologies and APIs. These classes are all located in the org.springframework.ws.server.endpoint package.

28. Which of the following is a feature of Spring Security?
a) Authentication
b) Method security
c) Authorization
d) All of the above
View Answer

Answer: a
Explanation: Spring Security provides comprehensive security services including method security, authentication, and authorization capabilities.

29. Integration of Spring which has each application produce files of shared data for others to consume.
a) Messaging
b) File transfer
c) Shared Database
d) Remote Procedure Invocation
View Answer

Answer: b
Explanation: File transfer: Have each application produce files of shared data for others to consume and consume files that others have produced.

30. Which of the following is used to handle exceptions globally in Spring MVC?
a) @ExceptionHandler
b) @ResponseStatus
c) @ControllerAdvice
d) @RestController
View Answer

Answer: c
Explanation: The @ControllerAdvice annotation is used to handle exceptions globally in Spring MVC, allowing you to define a single exception handling component for multiple controllers.

31. To take an input file or a payload and reliably, and systematically, decompose it into events that an ESB can work with:
a) Splitter
b) Spring Batch
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: b
Explanation: You have a file with a million records in it. This file’s too big to handle as one event; it’s far more natural to react to each row as an event. Spring Batch works very well with these types of solutions. It allows you to take an input file or a payload and reliably, and systematically, decompose it into events that an ESB can work with.

32. Spring core framework provides first-class support for transactions.
a) TransactionManager
b) None of the mentioned
c) Transaction
d) All of the mentioned
View Answer

Answer: a
Explanation: You simply wire up a TransactionManager and give Spring Batch a reference, just as you would in any regular JdbcTemplate or HibernateTemplate solution.

33. Spring Batch provides a mechanism to offload processing to another process.
a) remote chunking
b) chunking
c) remote
d) none of the mentioned
View Answer

Answer: a
Explanation: Spring Batch provides a mechanism to offload processing to another process. This feature, called remote chunking, is new in Spring Batch 2.x.

34. Spring Dynamic Modules was, while powerful for those already invested in an OSGi platform, not the most natural accommodations for those trying to migrate large code into the OSGi environment, SpringSource created.
a) SpringSource dm Server
b) Spring Tooling
c) Spring Dynamic Modules
d) All of the mentioned
View Answer

Answer: a
Explanation: SpringSource dm Server is a robust solution. There are several editions available.

35. Which of the following principles does the Spring Framework primarily rely on?
a) Inversion of Control (IoC)
b) Polymorphism
c) Encapsulation
d) Inheritance
View Answer

Answer: a
Explanation: The Spring Framework primarily relies on Inversion of Control (IoC), allowing the framework to manage the lifecycle of application objects (beans).

36. What is the purpose of the @Component annotation in Spring?
a) To specify a configuration class
b) To define a bean in the application context
c) To enable AOP support
d) To create a controller in Spring MVC
View Answer

Answer: b
Explanation: The @Component annotation is used to define a bean in the application context, indicating that a class is a Spring-managed component.

37. Which interface is used to create a Spring application context?
a) ApplicationListener
b) BeanFactory
c) WebApplicationContext
d) ApplicationContext
View Answer

Answer: d
Explanation: ApplicationContext is a central interface to provide configuration for an application, and it is used to create Spring application contexts.

38. To start using Spring to smooth over some of the minutiae of resource acquisition and to help build more reliable systems in an OSGi environment.
a) Spring Dynamic Modules
b) Spring DM server
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: a
Explanation: Use Spring Dynamic Modules to provide the integration. Spring Dynamic Modules is a framework on top of OSGi that works with any OSGi environment.

39. Spring-WS supports annotating an arbitrary class as a service endpoint by:
a) @Point
b) @End
c) @Endpoint
d) None of the mentioned
View Answer

Answer: c
Explanation: Spring-WS supports annotating an arbitrary class as a service endpoint by the @Endpoint annotation, without extending a framework-specific class.

40. The core interface of Spring email support is:
a) MailSender
b) EMail
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: a
Explanation: Spring email support makes it easier to send email by providing an abstract and implementation-independent API for sending email. The core interface of Spring email support is MailSender.

41. Spring Batch works with a system scheduler:
a) autosys
b) cron
c) none of the mentioned
d) all of the mentioned
View Answer

Answer: d
Explanation: Spring Batch works with a system scheduler such as cron or autosys, or from a web application.


Chapterwise Multiple Choice Questions on Spring

Spring MCQ - Multiple Choice Questions and Answers

Our 1000+ MCQs focus on all topics of the Spring subject, covering 100+ topics. This will help you to prepare for exams, contests, online tests, quizzes, viva-voce, interviews, and certifications. You can practice these MCQs chapter by chapter starting from the 1st chapter or you can jump to any chapter of your choice.
  1. Spring Basics and Advanced Spring IoC Container
  2. Spring AOP and AspectJ Support and Scripting in Spring
  3. Spring Security and Integrating Spring with Other Web Frameworks
  4. Spring Web Flow, Spring @MVC, Spring REST and Spring and Flex
  5. Grails, Spring Roo, Spring Testing and Spring Portlet MVC Framework
  6. Data Access, Transaction Management in Spring and EJB, Spring Remoting and Web Services
  7. Spring in the Enterprise, Messaging, Spring Integration and Spring Batch
  8. Spring on the Grid, jBPM and Spring, OSGi and Spring and Advanced Java

1. Spring Basics and Advanced Spring IoC Container

The section contains multiple choice questions and answers on creation and declaration of beans, scope of beans, bean processors, property editors and spring taskexecutors.

  • Creating Beans
  • Declaring Beans
  • Bean Scopes
  • Bean Post Processors
  • Property Editors and Task Executors in Spring
  • 2. Spring AOP and AspectJ Support and Scripting in Spring

    The section contains questions and answers on annotation of aspectJ, definition of pointcut, basics of behaviour and beans state, implementation,injection, refreshing and defining beans with scripting languages.

  • AspectJ Annotation
  • Pointcut Definitions
  • Introducing Behaviors and States to Your Beans
  • AspectJ Aspects
  • Implementing and Injecting Beans with Scripting Languages
  • Refreshing and Defining Beans from Scripts
  • 3. Spring Security and Integrating Spring with Other Web Frameworks

    The section contains MCQs on URL security, web security, view security, domain object security, integrating and accessing springs with frameworks, web flow management and security.

  • Securing URL Access
  • Securing Web Applications
  • Handling Security in Views and Domain object security
  • Accessing and Integrating Spring with known Frameworks
  • Managing Web Flows
  • Securing and Persisting Objects in Web Flows
  • 4. Spring Web Flow, Spring @MVC, Spring REST and Spring and Flex

    The section contains multiple choice questions and answers on integration of spring with JSF, MVC applications, mapping and handling of views, bean validation, REST with spring, JSON with REST, flex, sandbox and blazeDS.

  • Integrating Spring Web Flow with JSF
  • Spring MVC Web Applications and Requests Handlers
  • User Locales and Locale-Sensitive Text Messages
  • Views Mapping and Handling
  • Bean validation and Creating Excel and Pdf
  • REST Service with Spring
  • JSON with REST
  • Flex and Sandbox in Spring
  • Spring BlazeDS Support
  • 5. Grails, Spring Roo, Spring Testing and Spring Portlet MVC Framework

    The section contains questions and answers on grails, application domain classes, message and storage properties, unit testing and logging, integration testing, spring roo, portlet and tool suite, custom layouts, tags and templates.

  • Grails Application and Plugins
  • Application’s Domain Classes
  • Internationalization (I18n) Message Properties and Storage Properties
  • Logging and Unit Testing
  • Custom Layouts, Tags and Templates
  • Spring Roo
  • Spring Source Tool Suite
  • Unit Testing Spring
  • Integration Testing
  • Spring Portlet MVC
  • 6. Data Access, Transaction Management in Spring and EJB, Spring Remoting and Web Services

    The section contains MCQs on JDBC templates, exception handling, ORM frameworks, session, hibernate, EJB, web services and transaction management.

  • Problems with Direct JDBC
  • JDBC Template
  • Using the Simple JDBC Template and Handling Exceptions
  • ORM Frameworks
  • Hibernate’s and JPA’s Contextual Sessions
  • Transaction Management
  • Setting the Transaction Attribute
  • EJB 2.x with Spring
  • EJB 3.0 with Spring
  • SOAP Web Service
  • Spring Web Services
  • Web Services with XML Marshalling and Service End Points
  • 7. Spring in the Enterprise, Messaging, Spring Integration and Spring Batch

    The section contains multiple choice questions and answers on email and spring scheduling, JMX MBeans, system integration, error handling, splitters, aggregators, spring gateways and batch and controlling of step execution.

  • JMX MBeans
  • E-mail and Scheduling with Spring Support
  • JMS Messages and Transactions
  • Message-Driven POJOs in Spring and Making Connection
  • Integration of Systems
  • Transformation and Error Handling
  • Splitters and Aggregators, Routing
  • Spring Batch and Gateways
  • Spring Batch’s Infrastructure and Reading, Writing
  • Transactions and Retrying
  • Controlling Step Execution and Job
  • 8. Spring on the Grid, jBPM and Spring, OSGi and Spring and Advanced Java

    The section contains questions and answers on object clustering, process parallization, load balancing, OSGi, serialization and email API.

  • Clustering Object State Using Terracotta and Execution to a Grid
  • Parallelizing Processing and Load Balancing
  • Workflow Models and JBPM
  • Integrating JBPM 4
  • Building a Service and Business Process with Spring
  • Getting Started with OSGI
  • Spring Dynamic Modules
  • SpringSource dm Server and Toolings
  • Serialization in Java
  • Java Send Email API
  • If you would like to learn "Spring" thoroughly, you should attempt to work on the complete set of 1000+ MCQs - multiple choice questions and answers mentioned above. It will immensely help anyone trying to crack an exam or an interview.

    Wish you the best in your endeavor to learn and master Spring!

    advertisement
    Manish Bhojasia - Founder & CTO at Sanfoundry
    Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

    Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.