0% found this document useful (0 votes)
33 views2 pages

Q5. Explain The Role of Dispatcherservlet and Contextloaderlistener

Here are the autowiring modes in Spring: 1. no - No autowiring. The dependencies must be defined explicitly by <property> and <constructor-arg> elements. 2. byName - Autowiring by property name. Spring looks for a bean with the same name as the property. 3. byType - Autowiring by property type. Spring looks for a bean of the same type as the property to autowire. 4. constructor - Autowiring constructor. Spring looks for a constructor where arguments match the properties. 5. autodetect - Spring looks at constructors and properties and tries to determine the dependency by type or by name when possible.

Uploaded by

sachin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Q5. Explain The Role of Dispatcherservlet and Contextloaderlistener

Here are the autowiring modes in Spring: 1. no - No autowiring. The dependencies must be defined explicitly by <property> and <constructor-arg> elements. 2. byName - Autowiring by property name. Spring looks for a bean with the same name as the property. 3. byType - Autowiring by property type. Spring looks for a bean of the same type as the property to autowire. 4. constructor - Autowiring constructor. Spring looks for a constructor where arguments match the properties. 5. autodetect - Spring looks at constructors and properties and tries to determine the dependency by type or by name when possible.

Uploaded by

sachin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

 Singleton: Only one instance of the bean will be created for each container.

This is the default scope for the spring beans. While using this scope, make
sure spring bean doesn’t have shared instance variables otherwise it might
lead to data inconsistency issues because it’s not thread-safe.
 Prototype: A new instance will be created every time the bean is requested.
 Request: This is same as prototype scope, however it’s meant to be used for
web applications. A new instance of the bean will be created for each HTTP
request.
 Session: A new bean will be created for each HTTP session by the container.
 Global-session: This is used to create global session beans for Portlet
applications.

Q5. Explain the role of DispatcherServlet and ContextLoaderListener.

DispatcherServlet is basically the front controller in the Spring MVC application as it


loads the spring bean configuration file and initializes all the beans that have been
configured. If annotations are enabled, it also scans the packages to configure any
bean annotated with @Component, @Controller, @Repository or @Service
annotations.

Cont
extLoaderListener, on the other hand, is the listener to start up and shut down the
WebApplicationContext in Spring root. Some of its important functions includes tying
up the lifecycle of Application Context to the lifecycle of the ServletContext and
automating the creation of ApplicationContext.
Q6. What are the differences between constructor injection and setter
injection?

No. Constructor Injection Setter Injection


 1)  No Partial Injection  Partial Injection
 2)  Doesn’t override the setter property  Overrides the constructor property if both are
Creates a new instance if any modification Doesn’t create a new instance if you change
 3)
occurs property value
 4)   Better for too many properties  Better for a few properties.
Q7. What is autowiring in Spring? What are the autowiring modes?

Autowiring enables the programmer to inject the bean automatically. We don’t need
to write explicit injection logic. Let’s see the code to inject bean using dependency
injection.

You might also like