Spring Interview Questions Preparation Course
- 2.5 hours on-demand video
- 4 articles
- Full lifetime access
- Access on mobile and TV
- Certificate of Completion
Get your team access to 4,000+ top Udemy courses anytime, anywhere.Try Udemy for Business
- Understand Spring concepts
- Learn Spring Interview Questions
- Best practices of Spring
- Tricky questions on Spring
- Gain deep Spring knowledge
- Demand higher salary or promotion based on the knowledge gained!
Q. What is Spring framework?
Spring is development framework for Java programming. It is an open source development framework for Enterprise Java.
The core features of Spring Framework can be used in developing a Java Enterprise application.
It has many extensions and jars for developing web applications on top of Java EE platform.
With Spring we can develop large-scale complex Java applications very easily. It is also based on good design patterns like Dependency Injection, Aspect oriented programming for developing extensible feature rich software.
Q. What are the modules in Core Container of Spring framework?
Spring framework has a Core Container. Modules in Core Container are:
Spring Expression Language module
Q. What are the modules in Data Access/Integration layer of Spring framework?
Modules in Data Access/Integration Layer of Spring framework are:
JDBC module: An abstraction layer to remove tedious JDBC coding.
ORM module Integration layers for Object Relational Mapping
OXM module: An abstraction layer to support Object XML mapping.
Java Messaging Service (JMS) module: Module for producing and consuming messages.
Transactions module: Transaction Management for POJO classes
Q. What are the modules in Web layer of Spring framework?
Modules in Web Layer of Spring framework are:
- Web module: This provides basic web-oriented integration features.
- Servlet module: Support for Servlet Listeners.
- WebSocket module: Support for Web Socket style messaging.
- Portlet module: MVC implementation for Portlet environment.
Q. What is the main use of Core Container module in Spring framework?
As the name suggests, Spring Core Container is the core of Spring framework. It gives the basic functionality of the Spring. All the parts of Spring Framework are built on top of Core Container.
Its main use is to provide Dependency Injection (DI) and Inversion of control (IOC) features.
Q. What kind of testing can be done in Spring Test Module?
Spring Test Module provides support for Unit testing as well as Integration testing of Spring components. It allows using JUnit or TestNG testing frameworks. It also gives ability to mock objects to use the test code.
Q. What are the uses of AOP module in Spring framework?
AOP module is also known as Aspect Oriented Programming module. Its uses are:
Development of aspects in a Spring based application
Provides interoperability between Spring and other AOP frameworks
Supports metadata programming to Spring
Q. What are the benefits of JDBC abstraction layer module in Spring framework?
Spring provides JDBC abstraction layer module. Main benefits of this module are:
- Helps in keeping the database code clean and simple.
- Prevents problems that result from a failure to close database resources.
- Provides a layer of useful exceptions on top of the error messages given by different database servers.
- Based on Spring’s AOP module
- Provides transaction management services for objects in a Spring application
Q. What are the main uses of Spring MVC module?
Spring-webmvc module is also known as Web-servlet module. It is based on Web Model View Controller pattern.
Main uses of this module are:
- Integration of Spring with other MVC frameworks
- Supports IoC to provide clean separation of controller logic from business objects
- Provides clean separation between domain model code and web forms
- Allows developers to declaratively bind request parameters to business objects
Q. What is the main benefit of Inversion of Control (IOC) principle?
Inversion of Control (IOC) principle is the base of Spring framework. It supports dependency injection in an application. With Dependency Injection, a programmer has to write minimal code. It also makes easier to test an application.
Most important benefit is that it leads to loose coupling within objects. With loose coupling it is easier to change the application with new requirements.
Q. Does IOC containers support Eager Instantiation or Lazy loading of beans?
IOC Container in Spring supports both the approaches. Eager instantiation as well as lazy loading of beans.
Q. What are the benefits of ApplicationContext in Spring?
ApplicationContext in Spring provides following benefits:
- Bean factory methods: These are used to access application components
- Load File Resources: It helps in loading file resources in a generic fashion
- Publish Events: It enables publishing events to registered listeners
- Internationalization Support: Ability to resolve messages to support internationalization
- Parent Context: Ability to inherit from a parent context
Q. How will you implement ApplicationContext in Spring framework?
ApplicationContext in Spring can be implemented in one of the following three ways:
FileSystemXmlApplicationContext: If we want to load the definitions of beans from an XML file then FileSystemXmlApplicationContext is used. The full path of XML bean configuration file is provided to the constructor.
ClassPathXmlApplicationContext: To loads the definitions of beans from an XML file in the CLASSPATH, we use ClassPathXmlApplicationContext. It is used for application context embedded in jars.
WebXmlApplicationContext: To provide configuration for a web application WebXmlApplicationContext is used. While the application is running, it is read only. But it can be reloaded if underlying application supports it.
Q. What are the main components of a typical Spring based application?
In a Spring based application, main components are:
- Spring configuration XML file: This is used to configure Spring application
- API Interfaces: Definition of API interfaces for functions provided by application
- Implementation: Application code with implementation of APIs
- Aspects: Spring Aspects implemented by application
- Client: Application at client side that is used for accessing functions
Q. What are the disadvantages of Dependency Injection (DI)?
Dependency Injection (DI) pattern has following disadvantages:
- Most of the time Dependency Injection forces developers to use an injection framework like Spring. This causes dependency on a framework.
- With Dependency Injection, clients are dependent on the configuration data. This becomes extra task for developers when the application does not need so many custom configuration values.
- Code is difficult to trace and read in Dependency Injection. DI separates behavior from construction of objects.
- Dependency injection increases complexity in the linkages between classes. It may become harder to manage such complexity outside the implementation of a class.
Q. What are the different ways to provide configuration metadata to a Spring Container?
Spring supports three ways to provide configuration metadata to Spring Container:
- XML based configuration: We can specify configuration data in an XML file.
- Annotation-based configuration: We can use Annotations to specify configuration. This was introduced in Spring 2.5.
- Java-based configuration: This is introduced from Spring 3.0. We can embed annotations like @Bean, @Import, @Configuration in Java code to specify configuration metadata.
Q. How will you define the scope of a bean in Spring?
In configuration xml, we can specify the scope of bean in its definition. This is used by container to decide the scope of bean in Spring.
E.g. <bean id="userService" class="com.um.UserService" scope="prototype"/>
This is an example of userService bean with prototype scope.
Q. Is it safe to assume that a Singleton bean is thread safe in Spring Framework?
No, Spring framework does not guarantee anything related to multi-threaded behavior of a singleton bean. Developer is responsible for dealing with concurrency issues and maintaining thread safety of a singleton bean.
Q. What is Bean wiring in Spring?
A Spring container is responsible for injecting dependencies between beans. This process of connecting beans is called wiring.
Developer mentions in configuration file, the dependencies between beans. And Spring container reads these dependencies and wires the beans on creation.
Q. What are the cases in which Autowiring may not work in Spring framework?
Autowiring is a great feature in Spring. It can be used in most of the cases. But there are certain scenarios in which Autowiring may not work.
Explicit wiring: Since Autowiring is done by Spring, developer does not have full control on specifying the exact class to be used. It is preferable to use Explicit wiring in case of full control over wiring.
Primitive Data types: Autowiring does not allow wiring of properties that are based on primitive data types like- int, float etc.
Q. Is it allowed to inject null or empty String values in Spring?
Yes, Spring allows injecting null or empty String values.
Q. What are the benefits of using Spring DAO?
Some of the benefits of using Spring DAO are:
It makes it easier to work on different data access methods like- JDBC, Hibernate etc.
It provides a consistent and common way to deal with different data access methods.
Spring DAO makes it easier to switch between different data persistence frameworks.
No need for catching framework specific exceptions.
Q. What are the different ways to use Hibernate in Spring?
Spring provides two ways to use Hibernate:
We can extend HibernateDAOSupport and apply an AOP interceptor node to use Hibernate.
We can also use HibernateTemplate and Callback to access Hibernate. This is based on Inversion of Control.
Q. What types of Object Relational Mapping (ORM) are supported by Spring?
Spring supports following Object Relational Mapping (ORM) frameworks:
- Java Persistence API (JPA)
- Java Data Objects (JDO)
- Apache Object Relational Bridge (ORB)
Q. How will you integrate Spring and Hibernate by using HibernateDaoSupport?
We can use following steps for integrating Spring and Hibernate:
- Add dependencies for Spring and Hibernate in pom.xml
- Implement DAO from HibernateDaoSupport
- Use Hibernate functions via getHibernateTemplate() method
Q. What is a Joinpoint in Spring AOP?
In Spring AOP, Joinpoint refers to a candidate point in application where we can plug in an Aspect.
Joinpoint can be a method or an exception or a field getting modified.
This is the place where the code of an Aspect is inserted to add new behavior in the existing execution flow.
Q. What is an Advice in Spring AOP?
An Advice in Spring AOP, is an object containing the actual action that an Aspect introduces.
An Advice is the code of cross cutting concern that gets executed.
There are multiple types of Advice in Spring AOP.
Q. What are the different types of Advice in Spring AOP?
Spring AOP provides five kinds of Advice:
- Before Advice: This type of advice runs just before a method executes. We can use @Before annotation for this.
- After (finally) Advice: This type of advice runs just after a method executes. Even if the method fails, this advice will run. We can use @After annotation here.
- After Returning Advice: This type of advice runs after a method executes successfully. @AfterReturning annotation can be used here.
- After Throwing Advice: This type of advice runs after a method executes and throws an exception. The annotation to be used is @AfterThrowing.
- Around Advice: This type of advice runs before and after the method is invoked. We use @Around annotation for this.
Q. What is a Proxy in Spring AOP?
In Spring AOP, a Proxy is an object created by the AOP framework to implement Aspect contracts. It is generally a JDK dynamic proxy or CGLIB proxy.
Q. What are the different types of AutoProxy creators in Spring?
Spring AOP provides following standard types of Autoproxy creators:
- BeanNameAutoProxyCreator: This is a BeanPostProcessor that creates AOP proxies for beans automatically by matching names.
- DefaultAdvisorAutoProxyCreator: This creator is more powerful that other Proxy Creators. This also applies eligible advisors automatically to bean in the current context.
- AbstractAdvisorAutoProxyCreator: This is the parent class of DefaultAdvisorAutoProxyCreator. We can create our own auto-proxy creators by extending this class.
- Basic Software knowledge
- Basic Spring knowledge
- Internet access
Spring is one of the most popular software framework for enterprise applications implemented in Java. Big companies like Amazon, Netflix, Google etc use Spring Framework in their Software development architecture. This course is designed to help you achieve your goals in Spring Framework field. Software Engineers with Spring Framework knowledge may get more salary than others with similar qualifications without Spring Framework knowledge.
In this course, you will learn how to handle interview questions on Spring Framework in Software Design and Development. I will explain you the important concepts of Spring Framework.
You will also learn the benefits and use cases of Spring Framework in this course.
What is the biggest benefit of this course to me?
Finally, the biggest benefit of this course is that you will be able to demand higher salary in your next job interview.
It is good to learn Spring Framework for theoretical benefits. But if you do not know how to handle interview questions on Spring Framework, you can not convert your Spring Framework knowledge into higher salary.
What are the topics covered in this course?
We cover a wide range of topics in this course. We have questions on Spring Framework best practices, Security. tricky questions etc.
How will this course help me?
By attending this course, you do not have to spend time searching the Internet for Spring Framework interview questions. We have already compiled the list of the most popular and the latest Spring Framework Interview questions.
Are there answers in this course?
Yes, in this course each question is followed by an answer. So you can save time in interview preparation.
What is the best way of viewing this course?
You have to just watch the course from beginning to end. Once you go through all the videos, try to answer the questions in your own words. Also mark the questions that you could not answer by yourself. Then, in second pass go through only the difficult questions. After going through this course 2-3 times, you will be well prepared to face a technical interview in Spring Framework.
What is the level of questions in this course?
This course contains questions that are good for a Fresher to an Architect level. The difficulty level of question varies in the course from a Fresher to an Experienced professional.
What happens if Spring Framework technology changes in future?
From time to time, we keep adding more questions to this course. Our aim is to keep you always updated with the latest interview questions on Spring Framework.
What are the sample questions covered in this course?
Sample questions covered in this course are as follows:
- What is Spring framework?
- What are the benefits of Spring framework in software development?
- What are the modules in Core Container of Spring framework?
- What are the modules in Data Access/Integration layer of Spring framework?
- What are the modules in Web layer of Spring framework?
- What is the main use of Core Container module in Spring framework?
- What kind of testing can be done in Spring Test Module?
- What is the use of BeanFactory in Spring framework?
- Which is the most popular implementation of BeanFactory in Spring?
- What is XMLBeanFactory in Spring framework?
- What are the uses of AOP module in Spring framework?
- What are the benefits of JDBC abstraction layer module in Spring framework?
- How does Spring support Object Relational Mapping (ORM) integration?
- How does Web module work in Spring framework?
- What are the main uses of Spring MVC module?
- What is the purpose of Spring configuration file?
- What is the purpose of Spring IoC container?
- What is the main benefit of Inversion of Control (IOC) principle?
- Does IOC containers support Eager Instantiation or Lazy loading of beans?
- What are the benefits of ApplicationContext in Spring?
- How will you implement ApplicationContext in Spring framework?
- Explain the difference between ApplicationContext and BeanFactory in Spring?
- Between ApplicationContext and BeanFactory which one is preferable to use in Spring?
- What are the main components of a typical Spring based application?
- Explain Dependency Injection (DI) concept in Spring framework?
- What are the different roles in Dependency Injection (DI)?
- Spring framework provides what kinds of Dependency Injection mechanism?
- In Spring framework, which Dependency Injection is better? Constructor-based DI or Setter-based DI?
- What are the advantages of Dependency Injection (DI)?
- What are the disadvantages of Dependency Injection (DI)?
- What is a Spring Bean?
- What does the definition of a Spring Bean contain?
- What are the different ways to provide configuration metadata to a Spring Container?
- What are the different scopes of a Bean supported by Spring?
- How will you define the scope of a bean in Spring?
- Is it safe to assume that a Singleton bean is thread safe in Spring Framework?
- What are the design-patterns used in Spring framework?
- What is the lifecycle of a Bean in Spring framework?
- What are the two main groups of methods in a Bean’s lifecycle?
- Can we override main lifecycle methods of a Bean in Spring?
- What are Inner beans in Spring?
- How can we inject a Java Collection in Spring framework?
- What is Bean wiring in Spring?
- What is Autowiring in Spring?
- What are the different modes of Autowiring supported by Spring?
- What are the cases in which Autowiring may not work in Spring framework?
- Is it allowed to inject null or empty String values in Spring?
- What is a Java-based Configuration in Spring?
- What is the purpose of @Configuration annotation?
- What is the difference between Full @Configuration and 'lite' @Beans mode?
- In Spring framework, what is Annotation-based container configuration?
- How will you switch on Annotation based wiring in Spring?
- What is @Autowired annotation?
- What is @Required annotation?
- What are the two ways to enable RequiredAnnotationBeanPostProcessor in Spring?
- What is @Qualifier annotation in Spring?
- How Spring framework makes JDBC coding easier for developers?
- What is the purpose of JdbcTemplate?
- What are the benefits of using Spring DAO?
- What are the different ways to use Hibernate in Spring?
- What types of Object Relational Mapping (ORM) are supported by Spring?
- How will you integrate Spring and Hibernate by using HibernateDaoSupport?
- What are the different types of the Transaction Management supported by Spring framework?
- What are the benefits provided by Spring Framework’s Transaction Management?
- Given a choice between declarative and programmatic Transaction Management, which method will you choose?
- What is Aspect Oriented Programming (AOP)
- What is an Aspect in Spring?
- In Spring AOP, what is the main difference between a Concern and a Cross cutting concern?
- What is a Joinpoint in Spring AOP?
- What is an Advice in Spring AOP?
- What are the different types of Advice in Spring AOP?
- What is a Pointcut in Spring AOP?
- What is an Introduction in Spring AOP?
- What is a Target object in Spring AOP?
- What is a Proxy in Spring AOP?
- What are the different types of AutoProxy creators in Spring?
- What is Weaving in Spring AOP?
- In Spring AOP, Weaving is done at compile time or run time?
- What is XML Schema-based Aspect implementation?
- What is Annotation-based aspect implementation in Spring AOP?
- How does Spring MVC framework work?
- What is DispatcherServlet?
- Can we have more than one DispatcherServlet in Spring MVC?
- What is WebApplicationContext in Spring MVC?
- What is Controller in Spring MVC framework?
- What is @RequestMapping annotation in Spring?
- What are the main features of Spring MVC?
- What is the difference between a Singleton and Prototype bean in Spring?
- How will you decide which scope- Prototype or Singleton to use for a bean in Spring?
- What is the difference between Setter and Constructor based Dependency Injection (DI) in Spring framework?
- What are the drawbacks of Setter based Dependency Injection (DI) in Spring?
- What are the differences between Dependency Injection (DI) and Factory Pattern?
- In Spring framework, what is the difference between FileSystemResource and ClassPathResource?
- Name some popular Spring framework annotations that you use in your project?
- How can you upload a file in Spring MVC Application?
- What are the different types of events provided by Spring framework?
- What is the difference between DispatcherServlet and ContextLoaderListener in Spring?
- How will you handle exceptions in Spring MVC Framework?
- What are the best practices of Spring Framework?
- What is Spring Boot?
- Fresher, Software Engineer, Sr. Software Engineer, Member Technical Staff, Expert
- Software Architect, Development Manager, Director
- Anyone who wants to appear in Spring interview
- People interested in going up in career!!