基本通知类
public class Notice {
public Notice (Object source)
{
//some constructor initialization.
}
}
特殊情况 OfferNotice 类
public class OfferNotice extends Notice {
public OfferNotice (Object source)
{
super(source);
//some constructor initialization.
}
}
GenericNoticeRecord 类
abstract public class GenericNoticeRecord <E extends Notice>
{
abstract public void recordNotice();
}
特殊情况 OfferNoticeRecord 类
class OfferNoticeRecord extends GenericNoticeRecord <OfferNotice>
{
private OfferNotice notice;
public void setNotice(OfferNotice notice) {
this.notice= notice;
}
public void recordNotice() {
// some implementation on Notice
}
}
在 MainService 类
中public class Mainservice {
private OfferNoticeRecord offerNoticeRecord;
public void send()
{
offerNoticeRecord.recordNotice();
}
}
在 App 类
中public class App {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
serv = context.getBean("MainService");
serv.send()
}
现在如何通过XML为此示例应用程序注入依赖项? 以下是我在XML Config中尝试的内容
<bean id="MainService" class="com.test.MainService">
<property name="offerNoticeRecord">
<ref bean="OfferNoticeRecordBean"/>
</property>
</bean>
<bean id="OfferNoticeRecordBean" class="com.test.OfferNoticeRecord">
<property name="notice">
<ref bean="OfferNoticeBean"/>
</property>
</bean>
<bean id="OfferNoticeBean" class="com.test.OfferNotice">
//here is major confusion, constructor is expecting source Object
</bean>