课程如下:
class ReportControllerBase {
String reportName = "Report";
public String getReportName() {
return reportName;
}
public void setReportName(String reportName) {
this.reportName = reportName;
}
// ...
}
class AnnualReportController extends ReportControllerBase {
// ...
}
class SkinCareAnnualReprotController extends AnnualReportController {
String productName;
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
基于 XML 的配置如下:
<bean id="annualReportController" class="AnnualReportController">
<property name="reportName" value="Annual Report"/>
</bean>
<bean id="annualSpecialReportController" class="AnnualReportController">
<property name="reportName" value="Annual Special Report"/>
</bean>
<bean id="skinCareAnnualReprotController" class="SkinCareAnnualReprotController" parent="annualReportController">
<property name="productName" value="A famous skin care product"/>
</bean>
Bean AnnualReportController和AnnualSpecialReportController是同一个 Class 的实例。并且skinCareAnnualReprotController继承自 bean AnnualReportController。
如何在 Spring 中基于注解的配置中实现此配置?