- Is it safe to have such a hierarchy of contexts? For example, if there are 30 child contexts?
What do you mean by security? If you mean thread safety when initializing a bean, then yes, because contexts are initialized one by one.
- What about cross-child bean context transparency? Say I have a CustomerService bean with @Component annotation with several DAO dependent dependencies. Does Spring do auto-automation and other DI actions in a specific child context?
Beans are not displayed in child contexts. The only beans visible in the context are its own and those contained in its parent contexts.
- Also, I'm going to look for beans from a child context using the following method: childContext.getBean (CustomerService.class); Am I getting customer service from this particular child context, and not another child context? I know that Spring singleton is a one-point application context, but still not sure.
Yes. In accordance with the answer to the last question.
I use this pattern quite widely in my applications. There is a common context that is shared by many other child contexts, making it its parent. This is very useful when you want to run completely isolated contexts within the same JVM, for example if you use mutli-tenant. Then you can start / stop / restart application contexts without using restarting the JVM.
It also provides a clear separation of data sources and transaction managers and makes it easy to outline their databases.
Abhinav sarkar
source share