Wildfly 8.2.0
我有一个Stateless
EJB和一个接口。
@Local
@Stateless
public class Bean implements IBean{
...
}
@Local
public interface IBean {
...
}
但我有焊接错误。如果Bean没有实现接口,就没有错误。根据https://stackoverflow.com/a/13988450/2023524和https://blogs.oracle.com/arungupta/entry/what_s_new_in_ejb应该没有错误。
错误:
WELD-001408: Unsatisfied dependencies for type Bean with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private mypackage.anotherBean.bean
更新:我已经尝试了Local
的所有可能组合,但无济于事。只有删除了接口,才不会出现错误。
@Stateless
public class Bean implements IBean{
...
}
@Local
public interface IBean {
...
}
//*****************************
@Stateless
public class Bean implements IBean{
...
}
public interface IBean {
...
}
//************************************
@Local
@Stateless
public class Bean implements IBean{
...
}
public interface IBean {
...
}
当您想通过EJB(使用@EJB
)或CDI(使用@Inject
)容器注入bean时,您可以声明一个具有接口类型的变量。在应用程序部署期间,容器可以找到已声明接口的具体实现。在您的示例中,问题不在于注释,而在于注入的声明类型(Bean
而不是IBean
)。
您需要从Bean中删除@Local
。
@Stateless
public class Bean implements IBean{
...
}
因为您定义了两种可能的局部焊接,所以不知道该使用哪一种。
oracle文档也通过@Remote
接口显示了这一点:
@Remote
public interface Foo { . . . }
@Stateless
public class Bean implements Foo, Bar {
. . .
}