LynAs LynAs - 1 year ago 216
Java Question

Spring get current ApplicationContext

I am using Spring MVC for my web application. My beans are written in "

" file

Now I have a class
and i want to access this class using spring bean

In the
i have written following

<bean id="myClass" class="com.lynas.MyClass" />

Now i need to access this using

ApplicationContext context = ??

So that I can do

MyClass myClass = (MyClass) context.getBean("myClass");

How to do this??

Answer Source

Simply inject it..

private ApplicationContext appContext;

or implement this interface: ApplicationContextAware

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download