Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring hierarchical context

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.

like image 304
Stefan Avatar asked Oct 27 '10 10:10

Stefan


People also ask

What is context hierarchy?

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.

Can we have 2 application context in Spring?

You can have two contexts within an application. If you have two contexts each will have its own singleton.

Can we have multiple context path in Spring boot?

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.


1 Answers

Here's a good post on how to do it: http://techo-ecco.com/blog/spring-application-context-hierarchy-and-contextsingletonbeanfactorylocator/

like image 149
Bivas Avatar answered Oct 19 '22 14:10

Bivas