I have following problem: I'm trying to implement Spring in existing ear application (using Jboss as App Server and Hibernate as ORM). The ear application consists of war(basically few simple servlets), har(hibernate archive which has only the data model-as classes and the corresponding hibernate mapping files - as xmls), sar(only one parsing class as scheduled task). So, I'm interested how can I share the eventual appContext of the har archive in the war (because servlets are retrieving data from the database) and in the sar(because the parser is "filling" the database). On that note, both (war and sar) should use the singleton SessionFactory bean that would be defined in the har's context. A code example or snippet would be highly appreciated.
A context hierarchy allows multiple child contexts to share beans which reside in the parent context. Each child context can override configuration inherited from the parent context. Furthermore, we can use contexts to prevent beans registered in one context from being accessible in another.
You can have two contexts within an application. If you have two contexts each will have its own singleton.
In order to have multiple context paths, you're limited to deploying the application multiple times with that convenient property set to what you want for each deployment. However, this is resource expensive because you're spinning up two applications for every one application you would normally spin up.
Here's a good post on how to do it: http://techo-ecco.com/blog/spring-application-context-hierarchy-and-contextsingletonbeanfactorylocator/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With