Issue
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??
Solution
Simply inject it..
@Autowired
private ApplicationContext appContext;
or implement this interface: ApplicationContextAware
Answered By - gipinani
Answer Checked By - Mildred Charles (JavaFixing Admin)