Top Spring Interview Questions & Answers

4.83 avg. rating (96% score) - 12 votes
spring-interview-questions

Spring is one of the most popular Java EE frameworks for developing web applications. Spring is based on J2EE technologies like JSP and Servlet along with the implementation of design pattern Model, View, and Controller.

We are compiling some crucial Spring interview questions and their answers that you must go through before appearing on Spring job interview.  

Q1. What is Spring MVC?

Ans.  Spring MVC follows the Model-View-Controller design pattern and implements basic features of a core Spring framework, including Inversion of Control and Dependency Injection.

Q2. Name different components of a Spring application.

Ans.  A Spring application has the following components:

  • Interface – Defines functions
  • Bean class – Consists properties, its setter and getter methods, functions etc.
  • Spring Aspect Oriented Programming (AOP) – Provides the functionality of crosscutting concerns
  • Bean Configuration File – Consists classes information and the ways to configure them
  • User program – Uses functions

Q3. What is a Spring configuration file?

Ans.  Spring configuration file is an XML file. It has information about the classes, interfaces and their dependencies.  It suggests how classes are configured and introduced to each other. It is very useful in managing projects if planned correctly.

Q4. Name various ways to use Spring Framework.

Ans.  Spring Framework can be used as –

  • Full-fledged Spring web application
  • Third-party web framework, using Spring Frameworks middle-tier
  • Enterprise Java Bean that can wrap existing POJOs (Plain Old Java Objects)
  • Remote usage

Q5. What are the benefits of Spring?

Ans.  The various benefits of Spring include –

  • It is versatile and non-invasive
  • It supports dependency injection and offers multiple modules to achieve different functionality for the development of application
  • It allows developers to develop enterprise-class applications using POJOs
  • It can remove the creation of factory classes

Q6. How can a Spring file be converted to Java?

Ans.  A Spring file be converted to Java By using Spring’sClassPathXmlapplicationContext from Java to set the Spring configuration.

 

Also Read>> Top Java Interview Questions & Answers

 

Q7. What are the different types of transaction management supported by Spring?

Ans.  There are two types of transaction management supported by Spring, that include –

  1. Programmatic transaction management
  2. Declarative transaction management

Q8.  What are the different bean scopes in Spring?

Ans.  The Spring supports five bean scopes, which are:

  1. Prototype
  2. Request
  • Singleton
  1. Global session
  2. Session

 

Q9. What are some of the vital Spring modules?

 Ans.  Some of the vital Spring modules are:

  • Spring AOP
  • Spring JDBC
  • Spring MVC
  • Spring Web Module
  • Spring Context
  • Spring DAO






Q10. Name some AOP concepts.

Ans.  Different types of AOP concepts are –

  • Interceptor
  • Joinpoint
  • Aspect
  • Target object
  • Weaving
  • Pointcut
  • Advice
  • AOP proxy

 

Q11. How can you configure Spring into the application?

Ans.  There are three ways to configure Spring into the application, which are –

  1. Java-based configuration
  2. XML based configuration
  • Annotation-based configuration

Q12. Are Spring singleton beans thread-safe?

Ans.  No, Spring singleton beans are not thread-safe.

Q13. Name the types of advice in AOP.

 Ans.  There are 5 types of advice in AOP –

  1. Throws advice
  2. Around advice
  • After returning advice
  1. Before advice
  2. After advice

 

Q14. Singleton Scopes are used with?

Ans.  Singleton Scope is used with Stateless session bean.

Q15. What do you mean by Introduction?

Ans.  Introduction enables the user to add new attributes and methods to existing classes.

 

Q16. What are important JDBC API classes?

Ans.  Following are some of the important JDBI API classes:

  • Simple jdbcCall
  • NamedParameterJdbc Template
  • Simple Jdbcinsert
  • Jdbc Template

Q19. Which would you consider, Play framework or Spring MVC?

Ans.  I would go with Spring MVC with these reasons:

  • Availability of ample resources on Spring MVC.EBOOK
  • It renders a very clean division among views, controllers and JavaBean models
  • Truly view-agnostic
  • It has a better testable code and ensures better integration with view technologies

Q20. Which Object Relation Mapping (ORM) does Spring support?

Ans – Spring supports the following ORM –

  • IBatis
  • JDO
  • OJB
  • Hibernate
  • TopLink

Q21. How would you access hibernate with the help of Spring?

Ans.  There are two ways to hibernate using Spring:

  • By extending hibernateDaoSupport and spreading over an AOP interceptor
  • By inversion of control (IOC) with a HibernateTemplate and Callback

 

Q23. Explain JoinPoint.

JoinPoint showcases a point in an application where we can plug in an abstract oriented programming aspect. This is the actual place where actions will be taken with the help of Spring AOP Framework.

Q24. Name some of the types of Autoproxying?

Ans.  Different types of Autoproxying are –

  • Metadata autoproxying
  • BeanNameAutoProxyCreator
  • DefaultAdvisorAutoProxyCreator

 

Q25. Can you inject an empty string value in Spring?

Ans.  Yes, we can inject an empty string value as the default value.

Q26. What is Dependency Injection?

Ans.  Dependency Injection is one of the important functionalities of Spring IoC (Inversion of Control) and is responsible for injecting dependencies through different processes, either through the Constructor or Setter method. Dependency Injection also ensures loose coupling between the classes.

 

Q27. What are the different types of Dependency Injection?

Ans.  Dependency Injection is of three ways –

  • Constructor injection – Here a class constructor provides dependencies
  • Setter injection – Here the client exposes a setter method used by the injector to inject the dependency
  • Interface injection – Here the injector method provides dependency

Only constructor and setter injections are used in Spring framework.

Q28. What are the benefits of using IoC?

Ans.  The primary benefits of IoC include –

  • Minimizes the number of codes in any application
  • Makes a platform/application easy to test, as it doesn’t need singletons or JNDI lookup mechanisms
  • Promotes loose coupling with less efforts and intrusive mechanism
  • Facilitates Eager Instantiation

 

Q29. What is a Spring Bean?

Ans.  Spring Bean is a crucial concept of the Spring Framework. Objects that form the base of any application and those managed by the Spring IoC container are called beAns.

Q30. Why is Spring bean configuration file necessary?

Ans.  Spring Bean configuration file can be used to define all the beans initialized by Spring Context. Spring Bean configuration file reads and initializes the Spring bean XML file when the instance of Spring ApplicationContext is created. These files can then be used to get different bean instances once the context is initialized.

Q31. What are Inner Beans?

Ans.  If a bean is using the property of another bean, it can be called an inner bean. Spring’s XML based configuration metadata defines the use of <bean> element inside the <property> or <constructor-arg>. Inner beans are anonymous.

Q32. What is Bean Wiring?

Ans.  If beans get combined within the Spring container, the structure is known as bean wiring. These beans are usually combined by using dependency injection method.

Q33. What is Bean Factory?

Ans.  Bean Factory is a Lightweight container that loads bean definitions and manages beAns.  These beans are configured using XML file and manage singleton-defined bean.

Q34. What are the different ways of controlling the life cycle events of a bean?

Ans.  There are 2 ways for controlling life cycle events of a bean –

  • InitializingBean and DisposableBean interfaces
  • Init-method and destroy-method

Q35.  What is Autowiring?

Ans.  Autowiring is a crucial feature in Spring framework, which uses setter or constructor injection and allows the user to inject the object dependency implicitly.

Q36. How many types of Spring Bean autowiring are there?

Ans.  Spring framework has four types of autowiring –

  1. autowire byName
  2. autowire byType
  • autowire by constructor
  1. autowiring by @Autowired and @Qualifier annotations

Q37. What is RowCallbackHandler?

Ans.  RowCallbackHandler is an interface used by JdbcTemplate to process rows of a ResultSet. It processes rows on a per-row basis.

Q38. What is AOP module?

Ans.  Aspect Oriented Programming (AOP) is a key component of the Spring framework. It allows interceptors to intercept an application. It can also be defined as the breaking of codes into different modules.

Q39. What is ViewResolver class?

Ans.  The ViewResolver class offers mapping between view names and actual views. It also allows the user to set properties like prefix or suffix to the view name.

Q40. Can you name different types of events of Listeners?

Ans.  Yes, there are 3 types of events of listeners:

  1. ContextClosedEvent – When the context is closed.
  2. ContextRefreshedEvent – When the context is initialized or refreshed
  • RequestHandledEvent – When the web context handles a request

Q41. What is weaving?

Ans.  Weaving is a process of applying aspects to the target object or other application types to create an advised object or a new proxy object.

Q42. On what points can you apply weaving?

Ans.  We can apply weaving on the following points –

  1. Compile Time
  2. Class load Time
  • Runtime

Q43. How can you control the database connection?

Ans.  Database connection can be controlled by using the following classes –

  • AbstractData Source
  • Data Source Utils
  • DataSource TransactionManager
  • DriverManager DataSource
  • SingleConnection DataSource
  • SmartData Source
  • TransactionAware DataSourceProxy

Q44. What is a Property Editor?

Ans.  Property editor is a feature of the JavaBeans API. This feature enables the conversion of property values to and from text values.

Q45. Name different editors used in Spring Framework.

Ans.  Different editors used in Spring Framework include –

  1. ClassEditor
  2. CustomDateEditor
  • FileEditor
  1. LocaleEditor
  2. PropertyEditor
  3. StringArrayPropertyEditor
  • StringTrimmerEditor
  • URLEditor

 

Q46. Which channels does Spring 2.0 support?

Ans.  Spring 2.0 supports the following channels –

  • Direct Channel
  • Executor Channel
  • Pollable Channel
  • Priority Channel
  • PublishSubscribe Channel
  • Queue Channel
  • Rendezvous Channel
  • Scoped Channel
  • Subscribable Channel

Q47. What are the new features in Spring 4.0?

 Ans.  Different features of Spring 4.0 include –

  • It manages Spring Bean lifecycle like JNDI lookup
  • It is used to create web applications and web services
  • All annotations are used to create custom composed annotations
  • It supports WebSocket-based communications in all web applications

Q48. What is the Web Module?

The web module provides basic web-oriented integration features and helps to create a web application without XML. After using the web module, a web.xml file needs to be configured.

Q49. What is DataAccessException?

DataAccessException is an unchecked RuntimeException. It is used to handle the errors occurring when the details of the database access API are being used.

Q50. How will you access Hibernate using Spring?

We can access Hibernate using Spring via two ways –

  • Inversion of Control with a Hibernate Template and Callback
  • Extending HibernateDAOSupport and Applying an AOP Interceptor node

Browse Courses by Categories

About the Author

Twinkle kapoor

Though from a techie background, her interest in writing on plethora of topics has made her today an experienced writer. She has written articles, blogs and web page content for oodles of websites.

Leave a Reply

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

*