Framework & Platform/Spring

spring - Get current ApplicationContext

linuxism 2014. 10. 6. 18:00


I am using Spring MVC for my web application. My beans are written in "spring-servlet.xml" file

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

In the spring-servlet.xml i have written following

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

Now i need to access this using ApplicationContext

ApplicationContext context = ??

So that I can do

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

How to do this??



@Autowired
private ApplicationContext appContext;



source - http://stackoverflow.com/questions/21827548/spring-get-current-applicationcontext