Announcement Announcement Module
No announcement yet.
Is it possible to share same Spring INSTANCE across WARs? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to share same Spring INSTANCE across WARs?

    Hi All,

    I would like to know that can we share SAME Spring Bean Instance (created in x.WAR) to another war(y.WAR).

    In my application there are number of beans like HibernateSessionFactory, DataSource etc which are same in all wars. And still they are getting created multiple times(n times for n war).

    I want to share same bean instance across multiple war.

    How can we achieve this in Spring?

    Please note: I know how to share ApplicationContext across war using "parentContextKey" (here its example). This will just share same xml not the instance.

  • #2
    Every WAR is a different application and spring context gets loaded for each application and therefore can't be shared. To reuse the DataSource & SessionFactory instance across multiple applications deployed in same application server, you need to configure these objects in JNDI and refer to those JNDI objects in different configuration within your application(s).