【发布时间】:2023-04-09 12:17:01
【问题描述】:
我想在加载应用程序上下文后调用一个方法。我使用了ApplicationListener 接口并实现了onApplicationEvent。
applicationContext.xml
<beans>
<bean id="loaderContext" class="com.util.Loader" />
<bean id="testServiceHandler" class="com.bofa.crme.deals.rules.handler.TestServiceHandlerImpl">
</beans>
Loader.java
public class Loader implements ApplicationListener {
public void onApplicationEvent(ApplicationEvent event) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
TestHandlerServiceImpl test = (TestServiceHandlerImpl)context.getBean("testServiceHandler");
}
}
但是上面的代码是递归的。是否可以从 onApplicationEvent 函数内的应用程序上下文中获取 bean?
【问题讨论】:
-
您再次加载应用上下文;不知道你会期待什么。使其具有上下文感知或其他功能。
标签: java spring spring-ioc