EJB: Dependency injection without Interface

烂漫一生 提交于 2019-12-23 20:45:29

问题


I had this code

@Local  
interface IRepo  
{  //...  
}  

@Stateless  
class Repo implements IRepo  
{  // ..  
}  

class WebS  
{  
@EJB private IRepo repo;  
// ...  
}  

And all worked normally.

But now I remove interface IRepo and make

@Stateless  
class Repo     {  // ..  
}  

class WebS  
{  
@EJB private Repo repo;  
// ...  
}  

and JNDI look up fails.

could not resolve global JNDI name for @EJB for container WebS ...   

Can I make Dependency injection without Interface?


回答1:


You should use

@Stateless
@LocalBean // <-- annotation here
class Repo     {  
}  

class WebS  
{  
@EJB private Repo repo;  
// ...  
}

Make sure you use EJB-3.1-compliant application server



来源:https://stackoverflow.com/questions/10498959/ejb-dependency-injection-without-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!