问题
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