Spring Interview Questions and Answers

by GangBoard Admin, January 29, 2019

In case you’re searching for Spring Interview Questions and Answers for Experienced or Freshers, you are at the correct place. GangBoard offers Advanced Spring Interview Questions and answers that assist you in splitting your Spring interview and procure dream vocation as Spring Developer.

Q1) What is Spring Core?

Answer:   Spring has been Architected in such a way the spring has been broken  down  into several parts these parts are called modules, there are several  modules are there with in the spring framework.  In that one module called spring core which is base module or infrastructure module that’s why unless until we learn the spring core we can’t learn rest of the module that are there with in the spring framework.      It supports managing the dependencies and managing complexity that are there  with the components.

Q2) How IOC container will create Object for Private constructor classes?

Answer: Spring internally will use reflection API and it will modify the constructor Accessibility and it will create the object of private constructor class also ,  by using reflection only Spring is doing autowiring and setting the objects into another object.

Q3) What is the purpose of BeanFactoryPostProcessor?

Answer: After  created BeanFactory and before using the bean if we need to change in the bean or if we need to add into the meta data then we will use BeanFactoryPostProcessors and we will add the data to metadata.

Q4) In SpringBeanConfiguration file for the same class 2 beans are there with different Bean names.Some other bean used Autowire ByType How we will replicate?

Answer: In Spring For the same class two objects is there and Another object used autowire ByType at that time we will use which bean don’t want to inject automatically for that bean we will add “autowirecandidate=false”

Q5) What are all the AOP advices used in Spring Transaction internally?

Answer: In Spring transaction internally two Advices they used. Before starting the operation it will start the transaction and if operation success it will call commit operation . Here Spring transaction used “Around Advice” and When Saving the Data Error came at that time it  will call rollback operation here they used “throws Advice”

Q6) How many AOP implementations Spring support? Why?

Answer: Spring supported Two types of AOP implementations it is provided.

1)Spring AOP


Because spring is a opensource and non-invassive framework. When the programmer want to go out of spring at that time if programmer used Spring AOP he cont able to go outside easily. That’s why spring provided AspectJ implementation also. AspectJ is third party implementation.

Q7) One-to-many relation ship how we will map objects in Spring JDBC?

Answer: In One-to-Many relational objects we need to implement “ResultSetExtractor” In Spring JDBC. It will get Result Set.inside that one we need to write our own logic to populate the data into objects and we need to give this ResultSetExtracter implemented class to JDBCTemplate class query method.

Q8) What is RowMapper? For which sake we will use RowMapper?

Answer: Spring JDBC don’t know how to Map the ResultSet into Objects. That’s why  we need to write a class by implementing RowMapper class. It will get ResultSet in side “mapRow” method we need to write populating logic and we need to give this RowMapper Object to “JDBCTemplate”  under query “method”.

Q9) What are all the annotations used in inside of @SpringBootApplication annotation?

Answer: The @SpringBootApplication annotation is using internally 2 annotaions are major.

Those are



Q10) What is CLI in SpringBoot? What is the use?

Answer: CLI (Commans Line Interface) it we need to download and install . If the programmer know how to implement the logic they can write the program and they will run the program with the Spring Command Line Interface. It can download all jars and it can deploy the project into internal Tomcat Embedded server.For very easy of developers they provided CLI.

Q11) Why spring provided Starter Dependencies?

Answer:For the easy of Developers Spring provided Starter dependencies. Normally Programmers are more concentrating on Configuration rather than business lolgic. For decreasing time to programmers on configuration dependency jars they provided starter dependencies. Internally they configured all dependencies.

Q12) In Spring AOP with which Advice programmer have a control?

Answer: With the Around Advice Proigrammer have a control of actual method execution.If the programmer did not called proceed() method actual method will not call.instead of actual method Aspect only will execute.Thats why we will call Around Advice as instead of Actual method .

Q13) Limitations of Dependency Injection


  • If we are using dependency injection it is good about managing the dependency between those components which are having the static references with each other.
  • If we have some dynamic dependency to be manage means the class whom I talk to will be decided by runtime instead of development time. Then dependency injection will not work.
  • We cannot use prototype scope bean in to singleton scope, because that prototype class behave like singleton only.

Q14) What is Bean Lifecycle?

Answer:Object for my bean is being created by the IOC container so the IOC container has to provide the mechanism for managing the birth of a bean and managing the death of a bean, so spring bean has provided life cycle methods for post construct activity and pre destroy activity on every bean, so bean life cycle comes in to picture.

Q15) Spring Internationalization

Answer: Spring has provided better support for internationalization when compared with JEE internationalization. It has provided multiple classes “ReloadableResourceBundleMessageResource” to support Internationalization.

Q16) Why spring integrated with AspectJ?

Answer: By Using spring AOP,the application is losing Non-invasiveness. So by avoiding the non-invasiveness spring people integrated Aspectj AOP with spring framework. Instated of using spring in implementing the AOP people stated using the Aspectj classes as part of spring work with Aop. So that      our application will become non–invasive.

Q17) How many times the static pointcut matches method will be called?

Answer:Depends on the number of method are present the target class to create the proxy. Once the proxy      has created only the number of method applied that method has been called and also 2 times extra for equals and hashcode.

Q18) How to work with Spring JDBC?

Answer: If I wanted to work with accessing the data from the database using Spring JDBC. Spring JDBC has provided 5 approaches in working with Spring JDBC to access the data from the database.   JDBC Template  Name parameters JDBC Template  Simple JDBC template  Simple JDBC insert or Simple JDBC call  Mapping SQL operations as sub classes.

Q19) Why Servlet called as Controller in spring?

Answer:Whenever we send the request from end user servlet container will receive the request but servlet container will never act as a controller because he never manages to send a response back to the end user. Servlet container will dispatch the request to the servlet component then servlet component will perform the operation. Always servlet will not do the same operation it depends on request URL, by looking at URL servlet will do the operation. Servlet will decide what it will do after getting the request from end user, so it is called decision maker so it is called as servlet.

Q20) What is Front Controller?

What is the purpose of front controller? Front controller is a design pattern. Front controller acts as one entry point of our application. If I want have controller over the request that is coming into my application ,such type of controlling request  can be happen if I  have one single getaway.  If we have front controller we can have better controller over managing the request. If the entire request coming to one getaway then it is easy to apply any kind of services. Like a validating the request can be applied at one place because all the request coming to the single entry point whether the request can be allow or should not be allow such kind of check or such kind of validate the easily acquired. Apart from that there could be some common mandatory system services will be there like form validating, request mapping etc… and plumbing services (optional) like audit will be managed by front controller. Rather than writing these logic in all the servlet Struts framework has provided a front controller to manage all the request.

Q21) What is the reason to create two inject with each other.

Answer:First of all spring is the non programmer to create two IOC dispatcher-servlet.xml one for spring specific applicationContext.xml one is for Business layer component means in future if we don’t want to use spring mvc then we can get read out from spring mvc easily without disturbing the existing business tire logic and we can replace any web component easily.

Q22) What is Handler Mapping? What is the purpose of Handler Mapping?

Answer: First the user send the request to the Application, Once the application get deployed. Context Loader Listener create IOC container after that before executing a particular Dispatcher Servlet, init() method gets called. And Dispactcher-servlet.xml file going to read by that init() method and create another IOC container. Once it finish Dispatcher Servlet takes the request and apply the common processing logic, system resources and plumbing logic and all once is finish it has to send to one of the controller to handle the request processing. But Dispatcher Servlet don’t no to which controller he has to send that particular request. So it is known to programmer means programmer has to tell to the Dispatcher Servlet to which controller he has to send that request .so to configure number of controller Handler Mapping comes to picture .

Q23) How dispatcher servlet know which Handler Mapping its has to go?

Answer: Its directly go to the IOC because it’s have the ref of Web Application Context as attribute .. Spring people has provide an interface all the handler Mapping are implementation from its so its always look for an Interface not the implementation class. Whatever you have wrote its search for Interface so we have to flexible of our own  Handler Mapping also we able to create. it is called polymorphism. Handler Mapping mapping=web Application Context.getBean ( SimpleUrlHandlerMapping.class);

Q24) When we should go for Abstract Wizard Controller?

Answer:It is the controller which help the developer to gather the data using multiple wizard. We cannot gather 100 of records or columns of data using jsp pages .it may load bad user experience to make good  and to gather the data mostly developer follow Wizard conversion and flow driven approach .

Q25) What is the Use of support(Class class) method and validator class of Validator class?

Answer:The support method holds the configured command class parameters and we can check whether the correct command class is configured or not using the  Class class type calling Assignable Form(class) method. If configure correctly it returns true otherwise it returns false ,so validate method will not execute. Due to  this we can avoid mis configuration in spring bean configuration file.

Q26) what is Handler interceptor?

Answer: We have one more additional component to Handler Mapping  is a Interceptor . So that whenever the Dispatcher Servlet received the request it forward the request to Handler Mapping , send the URl  , Handler Mapping  is trying to find is the URL is a relevant controller. If the controller is identified, the name of the controller along with that the Interceptor that should execute  for this controller both should be pass as the input for the Dispatcher Servlet.  Now  Dispatcher Servlet create Handler Execution chain because we can add any number of Interceptor like security interceptor, http Monitoring interceptor and logging interceptor .So multiple interceptor can apply for a request. So all the interceptor add to handler mapping . Handler Mapping will identify the controller and the list of Interceptor that has to be executed in the order before the request will goes to the controller it create  a  handler Execution Chain .

Q27) What are all the benefits of Spring ORM?

Answer:Easier Testing :Spring IOC approach allows you to swap easily  the implementations and configuration location of Hibernate Session Factory instances . so that you can point your configuration to various environment without modifying the source code.

Common data access Exception: Spring instead of exposing ORM specific checked exception to the top level tier’s of the application, It will wrap the technology specific exception in to a common runtime DataAccessException Hirarchy.

Integrated Transaction Management: Instead of dealing with ORM technology related transactional related code ,It allows You to declaratively manage the transactionality using AOP Declarative Transaction management tags <tx:advice or Annotation driven @Transactional annotation

Q28) Why Spring security Authenticate Provider will not validate the username and password ?

Answer: Validation logic must be rewritten in other class when we switch from one Authentication Store to other Authentication Store.  Validating the credential are be separate from fetching the credential from Authentication Store . Authentication provider will access the details and passes the input to the Authentication Manager.

Authentication Provider will fetch the username related record from the authentication store with which we need to compare the provider username and password is matching with the Authenticate username password . That mean the Authenticate provider we need to pass  the login username .Then he is going to pass User Details Object .User Details Object means Username, password, Role of the user will pass the input to Authentication Manager.

Q29) What does my Authenticate manager will do?

Answer:The authenticate manager will compare the user details with login user. If it is valid then it take the role of the user once it is identify role of user then it is going to the configuration file resource-authority.xml which resource can access by which authorization role user has to configure by the programmer . What are the resources are there in our system, and there resources are access by which role user will configure by us . Which is not automatic which is manually configure because i am the owner i am deciding which page is accessing by whom.

Q30) what is Spring Security?

To perform dependency injection on servlet filter component it can’t be possible because its class must be maintained by IOC container as spring bean having configuration in spring bean configuration file. Due to this it can’t take request from client as filter is not configured as web component in web.xml file. To overcome this problem we configure a special proxy filter in web.xml file to take the request from the client to pass the request to filter component that is there in IOC container as spring bean. The special filter is “org.springframework.web.filter.DelegatingProxyFilter”. But we need to match logical name  of DelegatingProxyFilter with bean name of filter component.

Q31) @Bean Annotation in which scenario we will use.

Answer: This annotation also we will use for creating the bean but we have another Stereo type annotations for creating bean. By using those annotation we will create a bean if we write the Source code.But some classes we will get from jars .class files. creating beans for .class files we will use @Bean annotation under JavaConfiguration class.

Q32) What is the difference between Spring non Annotation and Spring Annotation MVC.

Answer: Spring non annotation MVC flow programmer must and Should extedns from Any implementation of the controller of he need to implement the controller interface and Must and Should return value could be “ModelandView”. But Annotation flow programmer don’t need to implement any class. And we can return any value.

Q33) What is view Resolver? How many types of view Resolvers are there?

Answer: Dispatcher Servlet don’t know how to render View page. That’s why Spring people provided View Resolver. The reason is if Spring provided a implementation for rendering view also in Dispatcher Servlet if they need to modify anything related to View they need to modify Dispatcher Servlet. Because Dispatcher Servlet tightly couple with the View Resolver. That’s Why they provided different implementation. They Provided multiple implementations for View Resolver.

  • InternalResoureViewResolver
  • ResourceBundleViewResolver
  • XmlViewResolver
  • URLBasedViewResolver

Q34) Spring ORM based on which design pattern it implemented?

Answer: Spring ORM implemented Based on Template Design Pattern they implemented. This Template will support for All ORM frameworks like Spring JDBC , Hibernate , Ibattis in this way for every framework they implemented Template for every ORM implementation.

Q35) What is DataSource? What is the implementation spring provided for dataSource?

Answer: DataSource is a java provided interface for DataBase Connectivity. For this Every Web Server provided a implementation like Apache Tomcat , Weblogic , WebSphere etc. In the same way Spring also provided implementation  for DataSource that is called “DriverManagerDataSource”.

Q36) What is NamedParameterJDBCTemplate?

Answer: Normally writing Prepared statement programmer will confuse wich value we need to pass in which Positional paramer(?) in which place exactly programmer need to remember. But in NamedParameterJDBCTemplate we will not give Positional parameters like(?) , we will give proper name for that positional parameter(:name) like programmer will not confuse and te easy of programmer implemented NamedParameterJDBCTemplate.

Q37) Why Bean Factory Removed?

Answer: Spring provided two implementation for creating IOC container.

  • BeanFactory
  • ApplicationContext

BeanFactory for small scale application they provided and ApplicationContext for Enterprice Aplications. But Small scale applications very less number of Applciations only BeanFactory used. But Spring need to Provide a support for BeanFactory in everyRelease. That’s why in Spring 3.3 release tey removed BeanFactory from Spring.

Q38) How many ways we can break the singleton?

Answer: We can Break the Singlton in many ways those are

  • MultiThreading
  • Serislization
  • clone
  • Reflection etc.

If we restrict all these things then only we will get Complete Singleton class.

Q39) Write some points in springAOP and aspectAOP?



i)Only supports joinpoint is method Execution.

ii)Spring supports Runtime Viewing; this means the proxy object will be built on fly at runtime in the memory.

iii)Spring supports Static and Dynamic pointcuts.


i)It supports various types of join points like constructor Execution, method execution , field set or field get etc.

ii)AspectJ uses compile-time Weaving;this is indicates your proxy classes will be available wenever you compile your code.

iii)AspectJ supports only static pointcut.

Q40) Spring Security why we need to configure “DelegatingFilterProxy” class  must and sould we need to give name as “springSecurityFilterChain”?

Answer: Because Spring Internally configured the class as “SpringSecurityFilterChain” because of that we need to restric the as  “springSecurityFilterChain”. If we use any other name Spring cannot able to identify the class tats wy we need to give the same name.

Q41) What is the Spring Security internal Arcitecture flow?

Answer: First DelegatingFilterProxy will get the request and it will pass that request to Authentication manager to ask that URL is restricted or not if that is not restricted url that request will come back to DelegatingFilterProxy and it will forward to DispatcherServlet. Authentication Manager will search in the AuthenticationCOnfiguration file the URL is restricted or not. If the URL ir Restricted That will ask the details to AuthenticationProvider to get the details of the user and it will do the Authentication. If the User is Authorised User it will forward the URL to DispatcherServlet.

Q42) What is the Use of @PostConstruct and @PreDestroy annotations?


@PostConstruct: This annotation we will use in SpringBean Life cycle in annotation approach. This will execute that particular method after executing the constructor.

@PreDestroy: This Annotation will execute the method before executing finalize method or before exiting control from the program it will execute for pre destroy or complete activities.

Q43) What is Dependency Check in Spring?

Answer: In Spring Dependency Injection we will inject the Objects in two ways

  • ConstructorInjection
  • SetterInjection

if we use Constructor injection those dependencies are mandatory. But if we use Constructor Injection there is a chance of CyclicDependencyInjection. That time we need to go Mandatory SetterInjection only. If the Setter injection those are optional. With the SetterInjection we need to make those are mandatory we need to enable “DependencyCheck=true”.

Q44) What is BeanAlias in Spring?

Answer: For Spring Bean id if we need to give a multgiple names at that time we will use BeanAlias in Spring.

Ex: <bean id=”mobile” class=”Nokia”>

<alias name=”pone” alias=”mobile”>

Q45) How to rectify the “ContextLoaderListener” class not Found Exception wile deploing Application in WebServer.


  • Need to check weather the corresponding SpringWeb Jar is Added or not.
  • we need to Remove the files in temp folder of Our Web Aplication and we need to restart the server and then again we need to deploy the Application.
  • we need to check we are deploying correct War file or not.

Q46) What is the use of BeanPropertySqlParameterSource?

Answer: In Spring JDBC we need to map our object data to positional Parameters. But in NamedPArameterJDBCTemplate if we use we will give proper names in positional Parameter places. If tha all positional ParameterNames and the Business or DTO object class Variable Names are same Programmer don’t need to map we will give that BO object to BeanPropertySqlParameterSource and we will give this ParameterSource to NamedPArameterJDBCTemplate that will map internally.For the easy of programmers Spring provided this class.

Q47) What is method Replacement in Spring?

Answer: Spring provided a feature for for replacing the method logic at runtime. Rather than our actual mehod logic we will execute another logic. For this we need to Write a class by Implementing MethodReplacer and write the logic incide replacement metod. In Spring Bean Configuration File we need to create a bean for the Replacer class and in the Actual class bean we need to add the below Element.

<replaced-method name=”methodname” replace=”ReplaceClassBeanName”/>

Q48) What is the use of @Configuration use and wen we will use?

Answer: this annotation we will use if we used Pure Annotation based Approach at that time we will write one class For Configuration  class instead of SpringBean Configuration class. For Telling that class in Configuration class we will write this @Configuration annotation on top of that class.

Q49) What are all the StereoType Annotation Spring provided and Which scenario we need to use Which Annotation?

Answer: Spring provided 5 StereoType annotations

  • @Component
  • @Controller
  • @RestController
  • @Service
  • @Repository

All the above annotation will create a beans for the classes only. But we will use Specific Annotation in Specific Scenario only

@Component : this annotation we will this annotation just creating Bean but that class is not Related to any layer in Application.

@Controller : This Annotation we will use to Specifying that class as controller and it will create a bean for that class

@RestController : This Annotation we will use to Specifying that Controller class as RestController and it also creating Bean for that class

@Service : This Annotation we will use for the Specifying that class has Business Operation logic And that layer is Service Layer

@Repository : This Annotation we will use for DAO layer classes

Q50) What is the Use of RequestMappingHandlerAdapter?

Answer: DispatcherServlet cannot call by passing Requeired Parameters of the controller.It can pass only Request and Response and it will Take the Return Type as ModelAndView only. That’s why Spring released “RequestMappingHandlerAdapter”. Dispatcher Servlet will call this Adapter by passing handlerMethod and Request and Response. It will call the controller by passing Convenient and RequiredAttribute and it will get the response what ever the way controller is sending and it will place into the ModelAndView and send to the “DispatcherServlet”.


No Comments

Leave a Reply

Your email address will not be published Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Online Training Quick Enquiry

Get Free Online training