Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Sam Mercs wrote:I sure you could try it out pretty easily
![]()
If you've looking for a 'guess' I would say each IOC container would be separate beans, I don't see why spring should be merging "beans" from different containers unless its explicitly designed to do something like that (e.g. WEB-Application context -- a single root context per application, while each servlet in the application has its own child context)
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Please be aware that Spring's concept of a singleton bean is quite different from the Singleton pattern as defined in the seminal Gang of Four (GoF) patterns book. The GoF Singleton hard codes the scope of an object such that one and only one instance of a particular class will ever be created per ClassLoader. The scope of the Spring singleton is best described as per container and per bean.
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
If you've looking for a 'guess' I would say each IOC container would be separate beans, I don't see why spring should be merging "beans" from different containers unless its explicitly designed to do something like that (e.g. WEB-Application context -- a single root context per application, while each servlet in the application has its own child context)
Mark Spritzler wrote:In a Spring MVC app you will create 2 ApplicationContexts. One for the web layer Spring MVC components, and one for the middle tier. The Web Layer beans will have complete access to the Middle Tier one, but not the other way around.
In Spring MVC in your web.xml you deploy a DispatcherServlet with a config file(s) for the web layer beans and you deploy a ContextLoaderListener with a config file(s) for the middle tier. This creates what we call a parent-child ApplicationContext relationship. The web layer beans are in the child application context and the middle tier in the parent. Child beans can see parent beans, but parent beans cannot see child beans.
Mark
ApplicationContext instances in Spring can be scoped. In the web MVC framework, each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined in the root WebApplicationContext. These inherited beans defined can be overridden in the servlet-specific scope, and new scope-specific beans can be defined local to a given servlet instance.
Perry Terrance wrote:
This is interesting regarding this parent-child interaction. I am assuming though, that the MVC layer can see the Parent middle-layer Beans, but they cannot access those exact middle-layer Bean "instances" - per our Spring Singleton discussion correct? So while the MVC-layer can see the config file beans for the middle tier, it cannot access those exact instances if the middle-tier should so happen have ApplicationContext Spring Config calls in its internal code through its own internal Java logic and actually be modifying object fields in that specific IoC Container...
Whatever the MVC layer grabs will be always be in its own IoC Container instance, but with a Bean setup that includes the parent-level Bean configurations as well as its own Bean configuration?
I hope I am understanding this right....
Mark Spritzler wrote:
Perry Terrance wrote:
This is interesting regarding this parent-child interaction. I am assuming though, that the MVC layer can see the Parent middle-layer Beans, but they cannot access those exact middle-layer Bean "instances" - per our Spring Singleton discussion correct? So while the MVC-layer can see the config file beans for the middle tier, it cannot access those exact instances if the middle-tier should so happen have ApplicationContext Spring Config calls in its internal code through its own internal Java logic and actually be modifying object fields in that specific IoC Container...
Whatever the MVC layer grabs will be always be in its own IoC Container instance, but with a Bean setup that includes the parent-level Bean configurations as well as its own Bean configuration?
I hope I am understanding this right....
Nope. The Spring MVC layer beans can access the Middle Tier Beans directly. I can inject a Bean from the middle tier application context into a bean in the mvc web layer application context.
So I have an OrderService and an OrderController. I can inject the one and only one instance of OrderService into the OrderController. Each instance is in a different ApplicationContext.
Mark
Mark Spritzler wrote:There is a distinction. In your first example you created two ApplicationContexts and passing it the same xml configuration. So the ApplicationContexts each would instantiate objects from that configuration.
In the Spring MVC example you had two TOTALLY DIFFERENT configuration files. One that declared the middle tier beans and one that declared the web layer beans. You pass the web layer beans xml to the DispatcherServlet, and you pass the middle tier xml to the ContextLoaderListener.
And in Spring MVC the DispatcherServlet that creates the web layer ApplicationContext looks up the middle tier applciation context from the ServletContext and calls the setParent() method.
Mark