EJB:不带接口的依赖项注入 [英] EJB: Dependency injection without Interface
本文介绍了EJB:不带接口的依赖项注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此代码
@Local
interface IRepo
{ //...
}
@Stateless
class Repo implements IRepo
{ // ..
}
class WebS
{
@EJB private IRepo repo;
// ...
}
所有操作均正常。
但是现在我删除接口 IRepo
并制作
But now I remove interface IRepo
and make
@Stateless
class Repo { // ..
}
class WebS
{
@EJB private Repo repo;
// ...
}
,JNDI查找失败。
and JNDI look up fails.
could not resolve global JNDI name for @EJB for container WebS ...
我可以在没有接口的情况下进行依赖注入吗?
Can I make Dependency injection without Interface?
推荐答案
您应该使用
@Stateless
@LocalBean // <-- annotation here
class Repo {
}
class WebS
{
@EJB private Repo repo;
// ...
}
请确保使用符合EJB 3.1的应用服务器
这篇关于EJB:不带接口的依赖项注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文