我将接口定义为:
public interface DocExporter{
public void exportDoc();
}
将两个实现类定义为:
@Service(value="docExporter")
@Scope(value="BeanDefinition.SCOPE_PROTOTYPE)
public class PdfDocExporter implements DocExporter{
public void exportDoc(){
// do Pdf Export stuff
}
}
和
@Service(value="docExporter")
@Scope(value="BeanDefinition.SCOPE_PROTOTYPE)
public class ExcelDocExporter implements DocExporter{
public void exportDoc(){
// do Excel Export stuff
}
}
我可以这样说:
@Name("docExportReporter")
@Scope(ScopeType.EVENT)
public class DocExportReporter {
@In("#{docExporter}")
private DocExporter pdfDocExporter;
@In("#{docExporter}")
private DocExporter excelDocExporter;
@Asynchronous
public void reportGen(){
**excelDocExporter.exportDoc()** // THIS THROWS Seam Exception @In attribute requires a not null value
}
}
我是Seam with Spring的新手,想知道两个impl类中@Service的值是否为“docExporter”(接口名称)还是“pdfDocExporter”“excelDocExporter”?
如上所述,在reportGen异步方法中使用pdfDocExporter或excelDocExporter对象时,我得到@In属性需要非空值异常。可以在第三个类中声明接口的两个实现并且可以正常工作 使用Seam @Asynchronous注释?
答案 0 :(得分:0)
你不能有两个具有相同名称的组件,否则Seam不知道要注入哪个组件。使用两个不同的名称。