Special Offer - Enroll Now and Get 2 Course at ₹25000/- Only Explore Now!

All Courses
Spring Interview Questions and Answers

Spring Interview Questions and Answers

January 29th, 2019

Spring Interview Questions and Answers

In case you’re searching for Spring Interview Questions and Answers for Experienced or Freshers, you are at the correct place. Spring Interview Questions and Answers posted here will help you to crack the interviews easily as the entire list is prepared by well-experienced specialists. Starting from beginners’ level up-to advanced level, all the core concepts are discussed and published as questionnaires. If you are good in Spring framework, you will easily get selected in top-rated companies. The content discussed here comprises of various topics like Spring Framework, Spring features and advantages, Spring WebFlux, Spring Modules, Spring Life cycle, Spring security, best practices and design patterns available in Spring and many more. Spring is influential and trivial framework for application development that helps most of the roles like Spring Developer, Java Developer, Java Tech Lead and Software Developer. 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.

  • Spring AOP
  • AspectJ

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

  • @EnableAutoConfiguration
  • @ComponentScan

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?


  • Only supports joinpoint is method Execution.
  • Spring supports Runtime Viewing; this means the proxy object will be built on fly at runtime in the memory.
  • Spring supports Static and Dynamic pointcuts.


  • It supports various types of join points like constructor Execution, method execution , field set or field get etc.
  • AspectJ uses compile-time Weaving;this is indicates your proxy classes will be available wenever you compile your code.
  • 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.
<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”.

Q51) How to make scope has prototype?

Answer: By using the attribute scope=”prototype” in xml.

Q52) What are the attributes which helps to slove ambiguity problem in constructor dependence Injection?

Answer: By using type and index attributes in  xml.

Q53) What is mutual dependences?

Answer: When both the objects depending on each other we can call mutual dependences
example-A Object depends on B and B also depends on A.

Q54) What is depends on attribute?

Answer: It is used to indicate the one object has dependency of other.

Q55) What is the disadvantage of auto wiring?

Answer: It is helpful to inject only secondary types.

Q56) what is the difference between auto wire and @Autowired?

Answer: Auto wire- attribute used in xml for auto dependency injection.
@Autowired- used at method level or field level for auto dependency Injection.

Q57) How to solve the ambuguity problem when autowire is byType?

Answer: By using auto-wire-candiate=”false” tag in xml or
By using @Qualifer.

Q58) Spring container creates the objects instand of us we call it?

Answer: IOC(Inversion of control).

Q59) when we call getbean method two times for creating object when scope is default how many objects are created?

Answer: one object since the default scope is singleton.

Q60) What is the use of singleton attribute?

Answer: Attribute used to make singleton scope false. So becomes prototype.

Q61) What is the attribute used for secondary dependency Injection using Xml?

ans <property name=”fieldname” ref=”bean id”>

Q62) Which objects will be created by defalut when we inject list, set and map depedencies by xml?

Answer: List-ArrayList, Set-LinkedHashset, Map-LinkedHashMap

Q63) What are the methods present in FactoryBean Interface?

Answer: getObject(), getObjectType(), isSingleton()

Q64) What is the use of isSingleton() in FactorBean?

Answer: if it returns true then only single object will be cretaed for every request.

Q65) How to use look-up depenendence Injection?

Answer: By using the attribute <lookup-method >

Q66) How to use Initializing and Disposable Bean?

Answer: We need to implement Initializing Bean and override afterPropertySet() act like init method. we need to implement Disposable Bean and override destroy()

Q67) What is the use of PropertyPlaceHolderConfiguration class?

Answer: It is used to inject values which are present in properties file.

Q68) What is the use of hibernate template?

Answer: It is used at DAO layer directly we can perform save, update opertion by using methods like save update given by
hibernate template.

Q69) In which the run time exception occurs JDBC or Spring JDBC?

Answer: Spring JDBC

Q70) In Which data base connection close is mandatory JDBC or Spring JDBC?

Answer: JDBC

Q71) When we need to go for point-cut?

Answer: when we want to execute only the particular method berfore the bussiness logic.

Q72) How many command controllers are present?

Answer: 5

Q73) Which method is used to set the data source in jdbc template?

Answer: setDataSource()

Q74) What is the use of <context:annotation-config />?

Answer: It is used to enable @Autowired annotation

Q75) What is AutowiredAnnotationBeanPostProcessor?

Answer: It is also the class

Q76) What is the default handler mapping?

Answer: BeanNameUrlHandlerMapping

Q77) What are various handler mappings?

Answer: BeanNameUrlHandlerMapping, SimleUrlHandlerMapping, ControllerClassNameHandlerMapping

Q78) When to use BeanNameUrlHandlerMapping?

Answer: when we need matching to be done using name of the controller or by pattern.

Q79) What are @PostConstruct and @PreDestroy annotations?

Answer: They are used at method and methods act like init and destory

Q80) When to use After throwing advice?

Answer: when we want to execute service after any Exception.

Q81) What is spring-boot-starter-parent?

Answer: It is used to set-up spring boot application with maven.

Q82) What is @SpringBootTest?

Answer: It is annotation provied by spring boot for testing purpose.

Q83) What is the use of spring-boot-devtools?

Answer: It is used for auto reload of an appplication.

Q84) What are dependencies required in any application to make has JPA application?


Q85) one of the way for creating spring boot application?

Answer: By using Spring Initializr.

Q86) what is CrudRepository?

Answer: It is spring given interface used for curd operations on repository.

Q87) How to use CrudRepository?

Answer: We need to create our interface and extend curdrepository.

Q88) What is the use of Actuator in Springboot?

Answer: It is tool which is used for monitoring and managing the application

Q89) What is the use of application.properties in spring boot?

Answer: It configuration file in spring boot used to override all the default setups

Q90) What is H2 in Springboot?

Answer: It is the memory database given by spring

Q91) what is the default scope?

Answer: Signleton.

Q92) what is the difference between the application context and Bean factor?

Answer: application context creates the object at time of loading  but Bean factor creates the object at first request.

Q93) How to inject arraylist into a class through xml?

Answer: By using <list> tag

Q94) What are the Spring scopes?

Answer: Sigleton, prototype, request, session, global session.

Q95) Types of stereotype annotation?

Answer: @controller, @component, @Repository, @service

Q96) What is Session scope?

Session: It returns a single bean instance per HTTP session (User level session).

Q97) What are different types of Autowire?

Answer: There are four different types of Auto wire:

Q98) What Is Devtools In Spring Boot?

Answer: Spring boot comes with DevTools which is introduced to increase the productivity of developer.

Q99) What are types of pointcuts?

Answer: Static Method Matcher point cut
Name Method Matcher point cut

Q100) What are types of Advisors?


  • Defalut pointcut Advisor
  • Regex method pointcut Advisor

Q101) List out the major features in the versions of spring framework

Answer: The three (3) major features are as follows:

  1. Spring 2.5
  2. Spring 3.0
  3. Spring 4.0

Q102) Define Spring Framework

Answer: It is a Powerful Open source which has been created to reduce the complexity of application development. It is also termed as ‘framework of frameworks’ as it provides support to other frameworks such as hibernate, EJB, struts etc.

Q103) Give the advantages of spring framework

Answer: Advantages:

  • This enables Plain Old Java Object Programming which enables testability and continuous integration.
  • Due to Inversion and Dependency Injection of Control, JDBC has been simplified.
  • Since this a layered architecture, usage of components is manual.
  • This has no vendor lock-in as it is an open source architecture.

Q104) List out the different features in spring framework

Answer: Features of Spring framework

  • MVC framework
  • Lightweight
  • Inversion of Control
  • Aspect Oriented Programming
  • Container
  • Transaction Management

Q105) What is a Spring Configuration File?

Answer: Spring configuration file that has .xml extension and the entire file comprises of information on the interfaces, classes and its dependencies. Spring Configuration File is helpful when the spring container must control the spring bean life cycle. Dependency Injection can also be accomplished.

Q106) Define the different components of a Spring application?

Answer: The following are components of the spring application:

  • Interface defines the functions.
  • Bean class contains the setter and getter methods, properties, functions etc.
  • Spring Aspect Oriented Programming is one type which Provides the cross-cutting concern functionality.
  • Bean Configuration File is a type which contains the information of classes and how to configure them.

Q107) Define the two (2) types of IOC specifiers which are present in the spring.

Answer:  The two types are Application Context and Bean Factory.

  • Bean Factory – This contains the collection of beans and instantiates whenever needed by the client.
  • Application Context – This is constructed on the top of the bean factory. This also gives some more extra functionality on top when compared with bean factory.

Q108) Give the differences between bean factory and application context.

Answer: Difference between bean factory and application context:

  • Bean factory is an interface which has been defined in org. spring framework. beans. factory. Bean Factory whereas application context is defined in org. spring framework. context. ApplicationContext.
  • Bean factory uses Lazy Initialization while Application Context uses Aggressive or Eager Initialization.
  • Bean factory does not support internationalization whereas Application Context supports internationalization.

Q109) What are the benefits of IOC?

Answer: Some benefits of IOC are as follows:

  • This makes the application easy to test as it does not require any JNDI lookup mechanisms or singletons in unit test cases.
  • It supports loose coupling with least intrusive mechanisms and minimal effort.
  • It promotes lazy loading and eager instantiation of services.

Q110) What are the five (5) bean scopes supported by spring?

Answer: The bean scopes are given below

  • Singleton
  • Prototype
  • Request
  • Session
  • Global-Session

Q111) Define Auto Wiring and their modes

Answer: Spring container can auto wire the relationships between the collaborating beans. Here, Spring resolve the collaborators for bean automatically by inspecting the contents of the Bean Factory. Their modes are No, byName, byType, Constructor, autodetect.

Q112) Define dependency injection

Answer: It is a description of object creation. Services and components are not directly connected but to describe the services needed for the components in the configuration file. Wiring them together is done the IOC container.

Q113) What are the three ways in which injection dependencies can be done?

Answer: The three (3) ways to perform injection dependencies:

  • Setter Injection
  • Interface Injection
  • Constructor Injection

Q114) Give the differences between constructor Injection and Setter Injection.

Answer: Difference between constructor Injection and Setter Injection:

  • Partial Injection is not possible in the constructor injection whereas this is possible in setter injection.
  • Constructor injection cannot override the setter properties while setter injection overrides the constructor properties.
  • Many properties can be achieved through constructor injection whereas in setter injection only few properties can be achieved.

Q115) In the spring container, how are the configuration metadata are been provided?

Answer: In the spring container, the following configuration metadata can be provided

  • XML based configuration:
<bean id="employeebean" class="org. javaspring. firstSpring. employeebean">
<property name="student" value="javaspring"></property>
  • Annotation-Based configuration:
<context : annotation-configuration/>
<!-- bean description follows -->
  • Java based configuration:
public class employeeconfiguration
public EmployeeBean myemployee()
return new EmployeeBean();

Q116) What is meant by bean wiring in spring?

Answer: Within the spring container the beans are combined. This is termed as bean wiring.

Q117) Give the limitations with auto wiring

Answer: Limitations with auto wiring:

  • Confusing nature
  • Primitive datatype
  • Overriding possibility

Q118) Define @RequestMapping annotation

Answer: To map the HTTP request to any other class or method in the controller which handles requests, @RequestMapping is being used. The annotations can be appealed at two levels:

  • Class level
  • Method level

Q119) What are the exceptions which are been thrown by the spring DAO classes?

Answer: The below flowchart represents the Spring DAO classes in the hierarchical order. DAO classesàdaoàspring annotationsàjava spring.

Q120) What are classes which are present in spring JDBC API?

Answer: List of classes available in spring JDBC API:

  • SimpleJdbcTemplate
  • NamedParameterJdbcTemplate
  • JdbcTemplate
  • SimpleJdbcInsert
  • SimpleJdbcCall

Q121) In how many ways spring can be used to access hibernate?

Answer: There are two (2) ways in which this can be done:

  • IOC with call back and hibernate template.
  • Applying an AOP Interceptor node and Extending HibernateDAOSupport.

Q122) What are the two transaction management which spring supports?

Answer: The two-transaction management which spring supports are declarative transaction management and programmatic transaction management.

Q123) Define Aspect Oriented Programming

Answer: AOP is a technical programming model in which its behavior cuts across the typical divisions of responsibility also allows programmers to modularize crosscutting concerns. Transaction management and Logging are the main examples of cross cutting.

Q124) What is joinPoint?

Answer: Execution of programming results in a point called as joinPoint. In such a way of handling an exception or execution of a method. Method execution always represents a joinPoint.

Q125) What is an Advice?

Answer: At a joinpoint, an Action taken by an aspect is called as an Advice. Spring AOP uses an interceptor as an advice which maintains a chain of interceptors around the join point.

Q126) List out the different type of advices

Answer: Below are the list of advice types:

  • Before
  • After throwing
  • After returning
  • After (finally)
  • Around

Q127) Give the difference between Spring AOP and AspectJ AOP

Answer: Difference between Spring AOP and AspectJ AOP:

  • Via proxy, the runtime weaving is possible in Spring AOP while via AspectJ, the compile time weaving is possible.
  • Spring AOP is DTD based whereas AspectJ AOP is Schema and Annotation based.
  • Spring AOP underpins only method level Pointcut and AspectJ underpins field level pointcuts.

Q128) Define Proxy in Spring Framework

Answer: When applied an advice to a target object, a separate object is being created which is known as proxy. Proxy object and the target object are the same in case of client objects.

Q129) Explain term Weaving

Answer: An advised object is created while linking an aspect with other application types or object is said to be as weaving. This is usually performed at runtime. Given below is the arrow representation for the term weaving.

Q130) Give brief notes on Spring MVC framework

Answer: Spring MVC framework uses components which are ready to develop loosely coupled and flexible web applications. This also provides a model-view-controller architecture. Business logic, input logic and UI logic are some of the aspects which are separated by the MVC pattern and supply loose coupling between the elements.

Q131) What is meant by DispatcherServlet?

Answer: Spring Web MVC framework accommodate core called as DispatcherServlet. This also manages all the Http requests and responses. From the configuration file, this receives the entry of handler mapping and initiates the request to the controller. Now, the controller then sends an object of the model and the view in return. Now the DispatcherServlet calls the view component by checking the entry of the view resolver in the configuration.

Q132) What are the different AOP implementations?

Answer: There are three (3) type of AOP implementation. They are:

  • Spring AOP
  • Apache AspectJ
  • JBoss AOP

Q133) What are the six different ORMs which underpins spring?

Answer: ORMs which supports spring are:

  • JDO (Java Data Objects)
  • Hibernate
  • iBATIS
  • JPA (Java Persistence API)
  • Oracle Toplink
  • OJB

Q134) List out the roles of an IOC Container

Answer: IOC Container initially finds the beans. Then it wires the dependencies by identifying their respective dependency. Also, it manages the creation, processing and destruction phases which is said to be the lifecycle of the bean.

Q135) Define component scan

Answer: A request to the spring to detect spring-managed components. The input for this method is the below two packages.

  • Java Configuration
  • XML Configuration

Q136) Define Dirty Read

Answer: When transaction t1 is expected to read the changes in performance done by the transaction t2 but there the transaction t2 is not committed yet and such type of transaction in t1 is said to be as dirty read transaction.

Q137) What are the features which are now available in spring framework 4.0 and spring framework 0?

Answer: Spring framework 4.0 supports java features, Spring framework 5.0 supports Reactive programming and Kotlin.

Q138) Explain Front Controller

Answer: The first request will not be received by the servlet. The front controller initially gets the first request and then it is passed to the right servlet. Front controller is also called as the DispatcherServlet and then dispatches to appropriate controllers by intercepting all the requests from the client.

Q139) Explain the concepts which are available in the MVC controller.

Answer: Initially the DispatcherServlet receives a request from the browser. It can find the appropriate controllers as it knows the handler mapping. Controller returns the view name to the DispatcherServlet and put the data in the model by executing the request.

Q140) What is the main configuration of @SpringBootApplication?

Answer: The configuration are as follows:

  • @SpringBootConfiguration
  • @EnableAutoConfiguration
  • @ComponentScan

Q141) Explain the role of IOC container in the spring

Answer: IOC container is initially responsible to create the instance, configure the instance and also to assemble the dependencies. This is the way by which the IOC container is responsible.

Q142) How are the records fetched by the spring JDBC Template?

Answer: The records are fetched from the database by using the query method in the JDBC Template.
There are also interfaces to process this. They are:

  • Row Mapper
  • Result Set Extractor

Q143) List some of the AOP Terminologies

Answer: Some AOP Terminologies are:

  • JoinPoint
  • Advice
  • Pointcut
  • Aspect
  • Introduction
  • Target Object
  • Interceptor
  • AOP Proxy
  • Weaving

Q144) Explain ViewResolver in spring

Answer: By using the name it is used to resolve the implementations. It is configured in the spring bean configuration file.

<beans:property name="prefix" value="/WEB-INC/controller/" />
<beans:poperty name="suffix" value=".spring" />

Q145) What are the ways to create application context in java program?

Answer: There are three (3) ways to create:

  • AnnotationConfigApplicationContext
  • ClassPathXmlApplicationContext
  • FileSystemXmlApplicationContext

 Q146) List out some important spring annotations

Answer: There are many important annotations which are being used. Some of them are:

  • @controller
  • @RequestMapping
  • @ResponceBody
  • @PathVariable
  • @Autowired
  • @qualifier

Q147) How to use the Spring MVC Interceptor?

Answer: Spring MVC Interceptor allows to process by using the intercept client request as they are like servlet filters. The client filters can be intercepted at three places such as PreHandle, PostHandle, afterCompletion.

 Q148) Give the abbreviation for JDO and JPA

Answer: JDO – Java Data Objects and JPA – Java Persistence API.

Q149)  How to perform the component scan for spring boot?

Answer: @SpringBootApplication is the annotation to scan the performance. This automatically initiates the component scan on the package. This is the way in performing the component scan for the spring boot.

Q150) What are the different modules in Spring framework?


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

Q151) How can you fetch records by spring JdbcTemplate?

Answer: You can fetch records from the database by the query method of JdbcTemplate. There are two interfaces to do this:



Q152) What is  BeanFactory?

Answer: A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to separate the application’s configuration and dependencies from the actual application code.

Q153) What is AOP Alliance?

Answer: AOP Alliance is an open-source project whose goal is to promote adoption of AOP and interoperability among different AOP implementations by defining a common set of interfaces and components.

Q154) What is Spring configuration file?

Answer: Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other.

Q155) What are different types of Autowire types?

Answer: There are four different types by which autowiring can be done.

  • byname
  • byType
  • constructor
  • autodetect

Q156) What is the purpose of the session scope?

Answer: This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.

The idea here is that you have a web application, and you have various objects that exist on a per-session basis, such as maybe a user profile or a shopping cart. You’d like to make those available to some service bean, say, without having to manually pull them off the session and pass them as method arguments every time.

Q157) What is the default scope in the web context?

Answer: singleton

Q158)  Why are controllers testable artifacts?

Answer: Spring provides support for mockito framework for testing. Mockito provides MockMVC class is the main entry point of our tests. We can execute requests by calling its perform method.

Q159) What does the InternalResourceViewResolver do?

Answer: InternalResourceViewResolver is one of the implementation of ViewResolver for JSP templates. It is used to resolve “internal resource view” based on a predefined URL pattern. In additional, it allow you to add some predefined prefix or suffix to the view name (prefix + view name + suffix), and generate the final view page URL.

Q160) What’s internal resource views?

Answer: Those views under “WEB-INF” folder are named as internal resource views, as it’s only accessible by the servlet or Spring’s controllers class. In Spring MVC web application, for good practice, it’s always recommended to put the entire views or JSP files under “WEB-INF” folder, to protect it from direct access via manual entered URL.