【发布时间】:2011-10-25 16:38:58
【问题描述】:
有没有办法在 Spring 的 bean 配置文件中引用当前应用程序上下文?
我正在尝试做这样的事情:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="some-bean-name" class="com.company.SomeClass">
<constructor-arg>
<!-- obviously this isn't right -->
<bean ref=#{this}/>
</constructor-arg>
</bean>
问题是SomeClass 在其构造函数中需要一个 ApplicationContext 实例。有没有办法获取正在加载 bean 的 ApplicationContext 的引用?我知道我可以在 XML 中完成所有加载,但这并不是我所追求的,因为我需要在我的 java 代码中加载 bean。
【问题讨论】: