Top Spring Interview Questions & Answers

4.82 avg. rating (96% score) - 11 votes
spring-interview-questions

 

Spring questions have been designed to get you familiar with the nature of questions you may come across during your interview of spring. It is the best framework available to develop enterprise application in Java. If you have experience in Java based projects, you can easily answer interviewer questions.

We are compiling some Spring interview questions and answers that you must go through before appearing on spring job interview. This will create a well-rounded picture of the progress you are making towards achieving goals.

 

Q1. What are the benefits of spring?

 

Ans.

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

 

Q2. How can a spring file be converted to Java?

 

Ans. By using Spring’sClassPathXmlapplicationContext from Java to set the spring configuration.

 

Also Read>> Top Java Interview Questions & Answers

 

Q3. What are the kinds of transaction management supported by spring?

 

Ans. 

  • Programmatic transaction management
  • Declarative transaction management

 

Q4. Define Bean Wiring?

 

Ans. Blending beans with spring container is known as Bean Wiring. When spring finds out there is more than one bean that equals to injection point, it will inject one annotated with @primary.

 

Q5. What is IOC?

 

Ans. IOC stands for Inversion out of control. It is used to remove dependencies from the code.

 

Q6.  Name some bean scopes in spring?

 

Ans. The spring supports five scopes, which are:

  • Prototype
  • Request
  • Singleton
  • Global session
  • Session

 

Q7. What do you mean by AOP?

 

Ans. AOP means Abstract oriented programming. It is used in spring to render declarative enterprise services. Additionally, it covers some of the newer features like improved XML configurations, annotations and more.

 

Q8. When will you use singleton scope?

 

Ans. It is used with Stateless session bean.

 

Q9. What are some of the vital spring modules?

 

Ans. Some of the important spring modules are:

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

 

Q10. Name some AOP concepts?

 

Ans. 

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

 

Q11. How can you configure spring into application?

 

Ans. There are three ways to configure spring into application, which are Java based configuration, XML based configuration and Annotation based configuration.

 

Q12. Are spring singleton beans thread-safe?

 

Ans. No.

 

Q13. Name the types of advice in AOP?

 

Ans. 5 types of advice are as follows:

  • Throws advice
  • Around advice
  • After returning advice
  • Before advice
  • After advice

 

Q14. What are the new features in spring 4.0?

 

Ans. 

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

 

Q15. What do you mean by introduction?

 

Ans. It enables you to add new attributes and methods to existing classes.

 

Q16. Name the points where weaving are applied?

 

Ans. Weaving can be applied at compile time, runtime or at load time.

 

Q17. Can you explain two main methods of bean life cycle?

 

Ans. Setup and teardown are two methods that can be used on test cases.

 

Q18. 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:

  • Plenty of resources available on Spring MVC.EBOOK
  • Rendering a very clean division among views, controllers and JavaBean models
  • Truly view-agnostic
  • More testable code and better integration with view technologies

 

Q20. What are spring supports of Object Relation Mapping (ORM)?

 

Ans. 

  • IBatis
  • JDO
  • OJB
  • Hibernate
  • TopLink

 

Q21. How will you know when to use singleton scope bean?

 

Ans. It is used for stateless beans.

 

Q22. 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?

 

Ans. It 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. 

  • Metadata autoproxying
  • BeanNameAutoProxyCreator
  • DefaultAdvisorAutoProxyCreator

 

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

 

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

 

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.