Spring Core Interview Questions And Answers

 

Q1. What is Spring?

What is Spring
What is Spring




Q2. What is Bean in Spring framework and what are the different bean scopes?

What is Bean in Spring framework and what are the different bean scopes
What is Bean in Spring framework and what are the different bean scopes




Q3. How to add a bean in spring application?

How to add a bean in spring application
How to add a bean in spring application




Q4.  What are the different modules of Spring framework?

What are the different modules of Spring framework
What are the different modules of Spring framework




Q5.  What is the role of DispatcherServlet and ContextLoaderListner?

What is the role of DispatcherServlet and ContextLoaderListner
What is the role of DispatcherServlet and ContextLoaderListner




Q6.  What is the difference between constructor injection and setter injection?

What is the difference between constructor injection and setter injection
What is the difference between constructor injection and setter injection




Q7. What is autowiring in spring and what are the autowiring modes?

What is autowiring in spring and what are the autowiring modes
What is autowiring in spring and what are the autowiring modes




Q8. List some important annotations?

List some important annotations
List some important annotations




Q9.  What are some of the important Spring annotations used?

What are some of the important Spring annotations used
What are some of the important Spring annotations used




Q10. How to handle exceptions in Spring MVC Framework?

How to handle exceptions in Spring MVC Framework
How to handle exceptions in Spring MVC Framework





Q11. How to integrate Spring and Hibernate Frameworks?

How to integrate Spring and Hibernate Frameworks
How to integrate Spring and Hibernate Frameworks


Q12. What is the Bean life cycle in Spring Bean Factory Container?

What is the Bean life cycle in Spring Bean Factory Container
What is the Bean life cycle in Spring Bean Factory Container



Q13.What is the difference between @Component, @Controller, @Repository & @Service annotations in Spring?

What is the difference between @Component, @Controller, @Repository & @Service annotations in Spring
What is the difference between @Component, @Controller, @Repository & @Service annotations in Spring



Q14.What do you understand by @Required annotation?

What do you understand by @Required annotation
What do you understand by @Required annotation



Q15. What is circular dependency in spring?

It happens when  bean A depends on another bean B, and the bean B depends on the bean A as well:
Bean A → Bean B → Bean A
When Spring context is loading all the beans, it tries to create beans in the order needed for them to work completely. For instance, if we didn’t have a circular dependency, like the following case:
Bean A → Bean B → Bean C
Spring will create bean C, then create bean B (and inject bean C into it), then create bean A (and inject bean B into it).
But, when having a circular dependency, Spring cannot decide which of the beans should be created first, since they depend on one another. In these cases, Spring will raise a BeanCurrentlyInCreationException while loading context.
It can happen in Spring when using constructor injection; if you use other types of injections you should not find this problem since the dependencies will be injected when they are needed and not on the context loading.
A simple way to break the cycle is saying Spring to initialize one of the beans lazily. That is: instead of fully initializing the bean, it will create a proxy to inject it into the other bean. The injected bean will only be fully created when it’s first needed. One of the most popular workarounds, and also what Spring documentation proposes, is using setter injection.


Q16. What is the difference between session and global session?

globalSession is something that is connected to Portlet applications. When your application works in a Portlet container it is built of some amount of portlets. Each portlet has its own session, but if you want to store variables global for all portlets in your application then you should store them in globalSession. This scope doesn't have any special effect different from the session scope in Servlet-based applications.

Q17. What is application context in spring application?

So, it is the main component or we could say that it is the heart of spring core module. It manages the bean creation, bean life cycle, relations among the beans. It is also responsible ioc(inversion of control).

Q18.