Tuesday, 15 July 2014

java - Accessing cached ApplicationContext in spring -



java - Accessing cached ApplicationContext in spring -

i need fetch singleton bean same applicationcontext twice in 2 different classes.

example snippet :

class { public void foo(){ applicationcontext context = new classpathxmlapplicationcontext("common.spring.xml"); myparametrizedsingletonclass myparametrizedsingletonclass = (myparametrizedsingletonclass) context.getbean("myparametrizedsingletonclass"); // more stuff.. } class b { public void bar(){ applicationcontext context = new classpathxmlapplicationcontext("common.spring.xml"); myparametrizedsingletonclass myparametrizedsingletonclass = (myparametrizedsingletonclass) context.getbean("myparametrizedsingletonclass"); // more stuff.. }

since myparametrizedsingletonclass singletom if constructor called more 1 time same constructor arguments throws error.

how cache , reuse applicationcontext spring?

you creating 2 different context, if bean singleton create single instance per context,

if want cache application context you can create class , provide singleton instance of application context

java spring

No comments:

Post a Comment