【问题标题】:Seam Classes and @Asynchronous processing related issueSeam Classes 和 @Asynchronous 处理相关问题
【发布时间】:2012-09-24 14:22:06
【问题描述】:

我有一个接口定义为:

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

   }
  }

我是 Spring 的 Seam 新手,想知道在两个 impl 类中 @Service 的值是否为“docExporter”(接口名称)还是类似于“pdfDocExporter”“excelDocExporter”?

通过上述,当在 reportGen 异步方法中使用 pdfDocExporter 或 excelDocExporter 对象时,我得到 @In 属性需要非空值异常。接口的两个实现可以在第三个类中声明并且工作正常吗 使用 Seam @Asynchronous 注解?

【问题讨论】:

    标签: asynchronous seam


    【解决方案1】:

    你不能有两个同名的组件,否则Seam 将不知道要注入哪一个。使用两个不同的名称。

    【讨论】:

    • 但是 1) 如果您查看代码,它们是否应该没有相同的 @Service 注释,即 @Service(value="docExporter") 和 2) @In("#{SOMETHING}") 所暗示的内容,注入此“SOMETHING”(会话、对话或业务流程 Ctx)时的上下文是什么?
    • 是的,埃米尔,我在 faces-config.xml 文件中有这个设置,上面是一个示例示例,下面的 @Service 已经在我们的产品应用程序中工作。但是,当我尝试引入第二个 impl 时。接口的类,我得到 @Asynchronous 注释方法的错误 @In 需要非空属性。
    猜你喜欢
    • 2020-03-02
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多