WELD-001408 注入实现接口的 EJB 时依赖关系不满足

发布于 2024-12-29 04:29:42 字数 1251 浏览 6 评论 0原文

情况是这样的。

我有以下接口:

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:

@Named
@SessionScoped
public class TestController implements Serializable {

    @Inject
    private FirstBean firstBean;

    @Inject
    private SecondBean secondBean;
}

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

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接口,异常是一样的。
另外,我尝试添加限定符,但这并没有改变任何东西。

Here is the situation.

I've got the following interfaces:

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

and 2 EJBs:

@Stateless
public class FirstBean implements ChildOne { }

@Stateless
public class SecondBean implements ChildTwo { }

And also this CDI Bean:

@Named
@SessionScoped
public class TestController implements Serializable {

    @Inject
    private FirstBean firstBean;

    @Inject
    private SecondBean secondBean;
}

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)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

本宫微胖 2025-01-05 04:29:42

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

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

@Inject
private ChildOne firstBean;

即使定义了接口,也可以访问实现,这对于普通 CDI 托管 Bean(没有 @Stateless/@Stateful 注释的类)来说是可能的。所以去掉你的注释就可以了。

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

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

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;

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.

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.

最美不过初阳 2025-01-05 04:29:42

迟到总比不到好:

使用 @LocalBean 额外注释 SLSB 对我来说适用于 JBoss AS 7.1.1。我不喜欢创建没有附加值的界面的想法。

使用你的例子:

@Stateless
@LocalBean
public class FirstBean implements ChildOne { }

@Stateless
@LocalBean
public class SecondBean implements ChildTwo { }

Better late than never:

Annotating the SLSB aditionally with @LocalBean works for me with JBoss AS 7.1.1. I don't like the idea of creating the interface for no added value.

Using your example:

@Stateless
@LocalBean
public class FirstBean implements ChildOne { }

@Stateless
@LocalBean
public class SecondBean implements ChildTwo { }
奢望 2025-01-05 04:29:42

您是否尝试过使用 @EJB 注释而不是 CDI @inject 注释?

例如

@Named
@SessionScoped
public class TestController implements Serializable {

    @EJB
    private FirstBean firstBean;

    @EJB
    private SecondBean secondBean;
}

Have you tried using @EJB annotation rather then the CDI @inject annotation?

E.g.

@Named
@SessionScoped
public class TestController implements Serializable {

    @EJB
    private FirstBean firstBean;

    @EJB
    private SecondBean secondBean;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文