我正试图利用一个简单的例子来寻找注射方法。 但是,在通过这种方法注射针头方面似乎失败了。
我有一个简单的信条:
public class DemoBean {
private String message;
public DemoBean() {
}
public DemoBean(String message) {
this.message = message;
}
// Getter and Setter methods
@Override
public String toString() {
return "DemoBean{" +
"message= " + message + +
} ;
}
}
我试图将<密码>DemoBean注入另一个信条,即: 不动产:
public abstract class PropertyBean {
private DemoBean bean;
private String message;
// other members...
public PropertyBean(String message) {
this.message = message;
}
// Getter and Setter methods...
// Method for lookup injection
protected abstract DemoBean createBean();
@Override
public String toString() {
return "PropertyBean{" +
"bean=" + bean.toString() +
", message= " + message + +
", number=" + number +
} ;
}
}
Noe, there is my beans configuration:
<bean id="demobean" class="aro.discoverspring.beans.DemoBean" scope="prototype">
<property name="message" value="The Default Message!!!" />
</bean>
<bean id="propertybean" class="aro.discoverspring.beans.PropertyBean">
<constructor-arg name="message" value="A message in PropertyBean"/>
<lookup-method name="createBean" bean="demobean" />
</bean>
试图创建<代码>的事例 PropertyBean。 我能够这样做。 但当我做以下工作时。 我对DemoBean财产感到无足轻重的例外情况(因为海滩不会被注入!)
PropertyBean pb = (PropertyBean) ctx.getBean("propertybean");
System.out.println(pb.toString());
What am I doing wrong? Did I miss anything or am I overlooking something silly there!? Spring 3.0 reference (section 3.4.6.1) seems to be doing the same.