views:

80

answers:

2

I have a class


class ObjPool {
 MyObject getObject() {...}
 void returnObject() {...}
 int getUsedCount() {...}
}

How can we use Spring framework so that it would provide only one copy of this factory to all (web) applications and so that each and every application use the same ObjPool?

I mean if app A gets an object from this ObjPool, then all other applications that invoke getUsedCount() will see that value decremented.

+1  A: 

You could just google for "spring export to jndi"

http://maestro-lab.blogspot.com/2009/01/how-to-export-spring-managed-bean-to.html

org.springframework.jndi.JndiTemplate is a good place to start

Calm Storm
+3  A: 

In Spring each bean is a singleton by default, which means - one instance of the bean per ApplicationContext. This is NOT one per container, but one per web application.

http://blog.springsource.com/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/ gives an example of how to load an ApplicationContext at the EAR level and share across all wars.

JoseK