Q5. Explain The Role of Dispatcherservlet and Contextloaderlistener
Q5. Explain The Role of Dispatcherservlet and Contextloaderlistener
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.
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?
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.