如何依赖注入EJB3构造函数? [英] How to dependecy inject an EJB3 constructor?

查看:169
本文介绍了如何依赖注入EJB3构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 EJB3 DI文档可以注入字段和设置器。但是如何注入一个bean构造函数?

According to EJB3 DI documentation it is possible to inject fields and setters. But how to inject a bean constructor ?

推荐答案

EJB规范不支持构造函数注入。 EJB编程模型只使用no-arg构造函数,然后可以在构造实例之后执行字段或setter方法注入。

The EJB specification does not support constructor injection. The EJB programming model only uses the no-arg constructor, and can then perform field or setter method injection after the instance has been constructed.

那就是说,EJB 3.1是一部分的EE 6,其中包括CDI。如果您的EJB模块是CDI BDA(bean部署存档),因为它包含beans.xml,那么可以使用CDI构造函数注入。

That said, EJB 3.1 is part of EE 6, which includes CDI. If your EJB module is a CDI BDA (bean deployment archive) because it includes beans.xml, then you can use CDI constructor injection.

这篇关于如何依赖注入EJB3构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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