WELD-001408注入实现接口的EJB时不满意的依赖关系 [英] WELD-001408 Unsatisfied dependencies when injecting EJBs that implement interfaces

查看:132
本文介绍了WELD-001408注入实现接口的EJB时不满意的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是情况。

我有以下接口:

public interface Parent { }
public interface ChildOne extends Parent { }
public interface ChildTwo extends Parent { }

和2个EJB:

@Stateless
public class FirstBean implements ChildOne { }

@Stateless
public class SecondBean implements ChildTwo { }

CDI Bean:

And also this CDI Bean:

@Named
@SessionScoped
public class TestController implements Serializable {

    @Inject
    private FirstBean firstBean;

    @Inject
    private SecondBean secondBean;
}

在尝试将其部署到Glassfish 3.1上时,出现以下异常:

While trying to deploy this on Glassfish 3.1 I get the following exception:

Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [FirstBean]
with qualifiers [@Default] at injection point [[field] @Inject private com.test.controllers.TestController.firstBean]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [FirstBean] 
with qualifiers [@Default] at injection point [[field] @Inject private com.test.controllers.TestController.firstBean]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:305)

当两个EJB都实现 Parent 接口时,例外是相同的

另外,我尝试添加限定符,但这并没有改变。

When both EJBs implement the Parent interface, the exception is the same.
Also, I tried adding qualifiers, but that didn't change anything.

推荐答案

我只是玩弄您的构造,阅读一点焊缝 docu 并发现以下内容。

I just played around with your construct, read a bit of the weld docu and found out the following.

您正在使用实现接口的EJB,因此(显然)不再可以使用无接口视图,但是您尝试直接访问实现。一旦将其声明为EJB,就必须牢记约定。因此,如果定义接口,则必须使用它来访问EJB。将其更改为以下内容应该可以解决:

You are using EJBs that implement an interface, so the no-interface view is not possible anymore (obviously), but you are trying to directly access the implementation. As soon as you declare it as an EJB you have to keep in mind the conventions. So, if you define an interface you have to use it to get access to the EJB. Changing it to the following, should work out:

@Inject
private ChildOne firstBean;

即使对于纯CDI受管Bean,即使定义了接口,也可以访问实现(没有@ Stateless / @ Stateful注释)。因此,请摆脱注释,这样便可以解决问题。

Accessing the implementation even though an interface is defined is just possible for plain CDI Managed Beans (classes without the @Stateless/@Stateful annotations). So get rid of your annotation and it will work out.

仅供参考,如果您使用的是Glassfish。如果您坚持使用EJB并尝试访问父接口方法,则会遇到错误/异常。

Just for your information, if you are using Glassfish. If you stick to your EJBs and try to access the parent interfaces method you will run into this bug / exception.

这篇关于WELD-001408注入实现接口的EJB时不满意的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆