300+ [UPDATED] Spring MVC Framework Interview Questions

  1. 1. What Is A Spring?

    Spring is set to be a framework which helps Java programmer for development of code and it provides IOC container, Dependency Injector, MVC flow and many other APIs for the java programmer.

  2. 2. What Are Advices In Spring?

    It is the execution of an aspect. Advice is like making your application learn a new trick. They are usually introduced at joinpoints.

  3. J2EE Interview Questions

  4. 3. What Is The Default Scope Of Bean In Spring Framework?

    The default scope of bean is Singleton for Spring framework.

  5. 4. Name The Types Of Transaction Management That Are Supported By Spring?

    Transaction management supported by Spring are :

    • Declarative transaction management.
    • Programmatic transaction management.
  6. J2EE Tutorial

  7. 5. Is Singleton Beans Are Thread Safe In Spring Framework?

    No, singleton beans are not thread-safe in Spring framework.

  8. Hibernate

  9. 6. What Are The Benefits Of Spring Framework?

    Following are the benefits of Spring framework:

    • Extensive usage of Components
    • Reusability
    • Decoupling
    • Reduces coding effort by using pattern implementations such as singleton, factory, service locator etc.
    • Removal of leaking connections
    • Declarative transaction management
    • Easy to integrate with third party tools and technologies.
  10. 7. What Is Bean Factory?

    Bean Factory is core of the spring framework and, it is a Lightweight container which loads bean definitions and manages your beans.  Beans are configured using XML file and manage singleton defined bean. It is also responsible for life cycle methods and injects dependencies. It also removes adhoc singletons and factories.

  11. Hibernate Tutorial
    MVC Framework

  12. 8. Define Bean Wiring?

    Bean wiring is the creation of associations between application components that are between the beans in a particular spring container.

  13. 9. What Is Called Spring Mvc?

    A Spring MVC is a single shared controller instance and it is used to handle request type controllers, interceptors which run in the IoC container. It also allows multiple Dispatcher Servlets which can share application context interface but not class based interface.

  14. Framework7

  15. 10. Why Spring Framework Is Needed?

    Spring framework is needed because it is –

    • Very Light Weight Container
    • Framework
    • IOC
    • AOP
  16. MVC Framework Tutorial

  17. 11. Name The Various Modules Used In Spring Framework?

    • AOP module (Aspect Oriented Programming)
    • JDBC abstraction and DAO module
    • The Core container module
    • MVC framework module
    • Application context module
    • O/R mapping integration module (Object/Relational)
    • Web module
  18. Maven

  19. 12. Explain The Rowcallbackhandler In Spring?

    The RowCallbackHandler is called for each row in ResultSet and is used to read values from the ResultSet.

  20. J2EE Interview Questions

  21. 13. Define Application Context Module?

    This is a very important module and supplies various necessary services like EJB integration, remoting, JNDI access and scheduling. It transforms spring into a framework. It also broadens the idea of BeanFactory by application of lifecycle events, providing support for internationalization messages and validation.

  22. Framework7 Tutorial

  23. 14. Write About Aop Module?

    AOP module is utilized for creating aspects for Spring applications. It also enables support for metadata programming in Spring.

  24. 15. What Is A Beanfactory Interface?

    Bean factory interface is used to provide configuration framework for object creation and basic functionality around object management.

  25. JUnit

  26. 16. State The Differences Between Applicationcontext And Beanfactory In Spring?

    • ApplicationContext allows more than one config files to exist while BeanFactory only permits one.
    • ApplicationContext can print events to beans registered as listeners. This feature is not supported by BeanFactory.
    • ApplicationContext also provides support for application of lifecycle events, internationalization messages and validation and also provides services like EJB integration, remoting, JNDI access and scheduling. These features too are not supported by Bean Factory.
  27. Maven Tutorial

  28. 17. What Is Auto Wiring?

    Autowiring is used to build relationships between the collaborating beans. Spring container can automatically resolve collaborators for beans.

  29. Log4j

  30. 18. What Are The Different Modes Of Autowiring?

    Autowiring has five different modes:

    • no: no autowire
    • byName : Autowiring that can be done by property name
    • byType : property type as autowired
    • constructor: It is similar to byType and it is property is in constructor
    • autodetect :  Spring is allowed to select autowiring from byType or constructor
  31. Hibernate

  32. 19. How To Start Using Spring?

    Following steps needs to be done to start with the Spring:

    • Download Spring and its dependent file from spring’s site.
    • Create application context xml to define beans and its dependencies
    • Integrate application context xml with web.xml
    • Deploy and Run the application
  33. JUnit Tutorial

  34. 20. What Are The Methods Of Bean Life Cycle?

    There are two important methods of Bean life cycle:

    • Setup – called when bean is loaded into container
    • Teardown – called when bean is unloaded into container
  35. Java J2ee Architect

  36. 21. What Are The Different Types Of Events Of Listeners?

    Following are the different types of events of listeners: 

    ContextClosedEvent –
    This event is called when the context is closed.

    • ContextRefreshedEvent – This event is called when context is initialized or refreshed
    • RequestHandledEvent – This event is called when the web context handles request
  37. 22. Differentiate Between Singleton And Prototype Bean?

    Singleton means only one bean is defined per object instance while Prototype means one definition to more than one object instances in Spring.

  38. Log4j Tutorial

  39. 23. What Are The Types Of Dependency Injection?

    Two types of dependency injection are supported by spring framework:

    • Setter Injection
    • Constructor Injection
  40. Spring Boot

  41. 24. Write About Core Container Module?

    Core container module is responsible for the basic functionality of the spring framework. The whole Spring framework is built with this module as a base.

  42. MVC Framework

  43. 25. What Is Aop Module?

    This AOP module is used for spring enabled application. Support has been provided AOP alliance to ensure the interoperability between spring and other AOP frameworks.

    It instructs spring to add annotations to the source code and tell how to apply aspects.

  44. Spring MVC Framework Tutorial

  45. 26. What Is Aop Alliance?

    AOP alliance is an open-source project which is aimed at promoting adoption of AOP. The AOP alliance’s goal is to define a common set of components and interfaces so as to improve interoperability among different AOP implementations.

  46. Spring Batch

  47. 27. What Is Called Spring Configuration File?

    Spring configuration file is an XML file and it contains class information. It also describes how these classes are configured and interact with each other.

  48. Framework7

  49. 28. What Are Different Types Of Autowire?

    There are four different types of Auto wire:

    • byName
    • byType
    • constructor
    • autodetect
  50. 29. What Are The Types Of The Transaction Management That Is Supported By Spring?

    Following are the types of transaction management that has been supported by spring:

    • declarative
    • programmatically
  51. Spring Security

  52. 30. When Are Declarative And Programmatic Transaction Management Used?

    When only a small amount of transactional operations is there, it is advised to use Programmatic transaction management. But if there is a big amount of transactional operations to be taken care of, declarative transaction management is preferred.

  53. 31. What Is Ioc?

    IOC (Inversion of Control pattern) is also known as dependency injection. IOC directs the programmers to depict how to create objects instead of actually creating them. But in this design pattern, this control has been given to assembler and assembler will instantiate required class if needed.

  54. 32. Write About The Different Types Of Listener Related Events?

    The different types of events related to listeners are:

    • ContextRefreshedEvent – This gets called when the context is refreshed or initialized.
    • RequestHandledEvent – This gets called when the web context is handling a request.
    • ContextClosedEvent – This gets called when the context gets closed.
  55. 33. What Is An Aspect?

    Aspect is also called as logging which is required throughout the application. Logging or aspect is a cross cutting functionality in an application using AOP.

  56. Maven

  57. 34. What Is A Joinpoint?

    The point where an aspect can be introduced in the application is known as a joinpoint. This point could be a field being modified, a method being called or even an exception being thrown. At these points, the new aspect’s code can be added to introduce a new behavior to the application.

    Aspect code can be inserted at this point into normal flow of application to change the current behavior.

  58. 35. What Is Called An Advice?

    Advice will tell application on new behavior and it is the implementation of an aspect. It is inserted into an application at the joinpoint.

    Advice is the implementation of an aspect. It is something like telling your application of a new behavior. Generally, the advice is inserted into an application at joinpoints.

  59. 36. What Is A Pointcut?

    Pointcut is used to allow where the advice can be applied.

  60. JUnit

  61. 37. What Is Weaving?

    Weaving is used to create new proxy object by applying aspects to target object.

  62. 38. What Is Difference Between Singleton And Prototype Bean?

    Singleton Bean:
    – Single bean definition to a single object instance per Spring IOC container

    Prototype Bean:
    – Single bean definition to any number of object instances per Spring IOC Container

  63. 39. In What Points, Can Weaving Be Applied?

    Following are the points where weaving can be applied:

    • Compile Time
    • Class load Time
    • Runtime
  64. 40. What Are The Different Types Of Autoproxying?

    Following are the different types of AutoProxying:

    • BeanNameAutoProxyCreator
    • DefaultAdvisorAutoProxyCreator
    • Metadata autoproxying
  65. Log4j

  66. 41. How Can Beans Be Made Singleton Or Prototype?

    The bean tag has an attribute called ‘singleton’. The bean is singleton if its value is ‘TRUE’, otherwise the bean is a prototype.

  67. 42. What Classes Are Used To Control The Database Connection?

    Following are the classes that are used to control database connection:

    • Data Source Utils
    • SmartData Source
    • AbstractData Source
    • SingleConnection DataSource
    • DriverManager DataSource
    • TransactionAware DataSourceProxy
    • DataSource  TransactionManager
  68. Java J2ee Architect

  69. 43. Describe About Dao In Spring Framework?

    DAO is used to provide integration of Java database connectivity and Object relational mapping objects. DAO is spring framework provides connection for JDBC, hibernate, JDO, JPA, Common client interface and Oracle.

  70. 44. What Is Autoproxying?

    Autoproxying is used to create proxy automatically for the spring users.

    It provides following two classes to support this automatic proxy creation:

    • BeanNameAutoProxyCreator
    • DefaultAdvisorAutoProxyCreator
  71. 45. What Is Metadata Autoproxying?

    Metadata Autoproxying can be performed inspiring which can be driven by metadata. This is determined by source level attributes and keeps metadata inside the source code.

    This maintains metadata in one place and mainly used for declarative transaction support.

  72. 46. What Is ‘throws Advice’ In Spring?

    ‘Throws Advice’ define the behavior when an exception occurs. It is an interface and it has no methods which need to be implemented.

    A class that implements this interface should have method with this signature:

    • Void samplethrow (Throw table t)
    • Void samplethrow(Method m, Object[] o, Object target, Throw tablet)
  73. 47. What Are The Various Editors Used In Spring Work?

    The various custom editors provided by the Spring Framework are:

    • PropertyEditor
    • URLEditor
    • ClassEditor
    • CustomDateEditor
    • FileEditor
    • LocaleEditor
    • StringArrayPropertyEditor
    • StringTrimmerEditor
  74. 48. What Are The Advantages Of Spring Framework?

    Following are the advantages of spring framework:

    • Layered Architecture
    • Enables Plain Old Java Object (POJO) Programming and it enables continuous integration and testability
    • Dependency Injection and Inversion of Control that simplifies JDBC
    • Open source framework which can be used for commercial purpose
  75. 49. How Is Hibernate Accessed Using The Spring Framework?

    Hibernate can be accessed in the following two ways:

    • By IOC with a Callback and HibernateTemplate.
    • By applying an AOP Interceptor and broadening the HibernateDaoSupport.
  76. 50. What Are The Various Channels Supported By Spring 2.0?

    Following are the channels supported by spring version 2.0:

    • Pollable Channel
    • Subscribable Channel
    • PublishSubscribe Channel
    • Queue Channel
    • Priority Channel
    • Rendezvous Channel
    • Direct Channel
    • Executor Channel
    • Scoped Channel
  77. 51. Why Is Declarative Transaction Management Preferred In Spring?

    Declarative transaction management has minimum impact on the application code and, therefore, is an idealistic lightweight container.

  78. 52. Explain The Concept Of A Beanfactory?

    BeanFactory applies the idea of a factory pattern that utilizes IOC to separate the application’s dependencies and configuration from the actual code.

  79. 53. What Are The Different Scopes Of Spring Bean?

    Scopes of spring bean are Singleton, prototype, request, session and global session.

  80. 54. What Are All The Ways To Access Hibernate By Using Spring?

    There are two ways to access hibernate using spring:

    • Inversion of Control with a Hibernate Template and Callback
    • Extending HibernateDAOSupport and Applying an AOP Interceptor node.
  81. 55. What Is Inversion Of Control (ioc)?

    Inversion of Control (IOC) is also called as dependency Injection which is nothingbut a design pattern that gives control to the assembler of classes. In general, class will instantiate another class if required.

    But in this design pattern, this control has been to given to assembler and assembler will instantiate required class if needed.

  82. 56. Write The Benefits Of Using Ioc?

    The major benefits of dependency injection or IOC are that it reduces the amount of coding required for the application. This allows the testing of the application to be done quickly and easily as no JNDI lookup mechanism or singletons are required. IOC containers also support lazy loading and eager installation of services.

  83. 57. What Is Inner Bean? What Is The Drawback Of Inner Bean?

    If a bean element is directly embedded in a property tag while wiring beans, then the bean is called Inner Bean. Its drawback is that it cannot be reprocessed.

  84. 58. What Are The Different Types Of Injection In Spring?

    There are three types of Injection in spring:

    • Setter Injection
    • Constructor Injection
    • Getter or Method Injection
  85. 59. What Are The Types Of Advice?

    There are five types of Advice:

    • Before Advice
    • After returning advice
    • After throwing advice
    • Finally advice
    • Around advice
  86. 60. What Is Called Preparedstatementcreator?

    PreparedStatementCreator is one of the most commonly used interfaces for writing data to the database. createPreparedStatement() is a method that can be used to create and return PreparedStatement from the Connection argument, and exception handling is automatically taken care of. When this interface is implemented, a different interface SqlProvider can also be implemented which has a method called getSql(). This method is useful for providing sql strings to the JdbcTemplate. It does not handle SQLExceptions.

  87. 61. What Is Sqlprovider?

    SQLProvider has only one method called getSql()and it is implemented using PreparedStatementCreator implementers. It is mainly used for debugging.

  88. 62. Write About Batchpreparedstatementsetter?

    BatchPreparedStatementSetter is used to update more than a single row in one go, they can use BatchPreparedStatementSetter. This interface provides two methods they are

    • setValues( PreparedStatement ps, int i) throws SOL exception
    • int getBatchSize
  89. 63. What Is The Better Method Of Using Jdbc In Spring?

    If JDBC is used with the template class called JdbcTemplate, it gives a better performance.

  90. 64. Explain The Advantages Of Using Dao Module?

    The database code can be kept clean and simple by using the DAO module. This helps in preventing problems that rise because of poor handling of closures of database resources. Also, the DAO module utilizes the AOP module to enable objects in the Spring application to use transaction management services.

  91. 65. Name The Significant Applicationcontext Implementations Used In The Spring Framework?

    They are:

    • ClassPathXmlApplicationContext
    • FileSystemXmlApplicationContext
    • XmlWebApplicationContext
  92. 66. What Are Orm Integration Modules?

    Object/relational mapping (ORM) tool is supported by Spring over straight JDBC by implementing the ORM module. Spring can join various important ORM frameworks, including JDO, iBATIS SQL Maps and Hibernate.

  93. 67. Mention And Explain The Types Of Advice In Spring?

    Types of advice are:

    • Before advice: Advice that is executed prior to a joinpoint is called the ‘before advice’.
    • After returning advice: Advice that is executed after the normal completion of a joinpoint is called the ‘after returning advice’.
    • After throwing advice: Advice that is executed only if a method exits abnormally by throwing an exception, is called the ‘after throwing advice’.
    • After (finally) advice: Advice that is executed irrespective of how a joinpoint exits is called ‘after finally advice’.
    • Around advice: Advice that borders a joinpoint, for example, a method invocation, is called an ‘around advice’. This can be used to perform special activities before and after the invocation of method.
  94. 68. What Is The Web Module?

    The web module enables the creation of a web application without XML. The web.xml file needs to be configured for using the web module.

  95. 69. What Is Dataaccessexception?

    DataAccessException is a RuntimeException. It is an Unchecked Exception. The user cannot be forced to handle these kinds of exceptions.

  96. 70. What Is Xmlbeanfactory?

    Spring includes several applications of Bean factory. Out of these, org.springframework.beans.factory.xml.XmlBeanFactory is a very important one. It loads the beans on the basis of the definitions stored in an XML file. For the creation of an XmlBeanFactory, a java.io.InputStream is passed to the constructor. The InputStream provides the XML to the factory. For example, for retrieval of the bean, the getBean() method is called by passing the name of the desired bean.

  97. 71. Name The Exception Class Which Is Connected To The Exceptions Thrown By The Applications?

    It is the DataAccessException given by org.springframework.dao.DataAccessException

  98. 72. Mention The Types Of Loc (dependency Injection)?

    The different types of loC are: –

    • Setter Injection: With the help of JavaBeans properties.
    • Constructor Injection: Dependencies are given in the form of constructor parameters.
    • Interface Injection: With the help of an interface, an Injection is performed.

    Out of these three, only construction and setter are being used in Spring.

  99. 73. What Are The Important Beans Lifecycle Methods?

    All in all, two bean lifecycle methods are there. The first method is the setup method which is called during the loading of the bean into the container. The second is when the bean is unloaded from the container, and this method is called the teardown.

  100. 74. What Is A Target?

    A target is the class that is advised. This class can either be a class to which we want to add a special behavior to or a third party class. The target class is free to center on its major concern using the AOP concepts, regardless of any advice that is being applied.

  101. 75. Explain The Term Proxy?

    The term proxy refers to an object which is produced the application of an advice to the target object.

  102. 76. What Is Cross Cutting Concern And Concern In Spring Aop?

    Cross cutting concern:
     It is a concern which is applicable throughout the application and it affects the entire application. E.g Security, logging and data transfer are the concerns which are needed in almost every module of an application.

    Concern:
    Concern is a behavior that we want to have in a module of an application. Issues in which we are interested defines our concern.