2
public class A{
  private B b;
}

public class B{
}

应用程序上下文.xml

<bean id="aBean" class="A">
<property name="b">  ???  </property>
</bean>

使用时如何使用 b = null 创建 A 的实例context.getBean("aBean")

我试过了<property name="b"><null/></property>,但这不起作用。

4

2 回答 2

4

实际上,默认情况下它将为空。无需具体配置,即省略<property>元素。

而实际上

<bean id="aBean" class="A">
  <property name="b"><null /></property>
</bean>

应该工作:http ://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-null-element

于 2013-01-01T00:22:37.880 回答
-1

嗯?只是不要做任何事情。

<bean id="aBean" class="A"/>

在 Java中,对象引用默认为 null

于 2013-01-01T13:09:02.800 回答