EJB: dependency injection without an interface

I had this code

@Local  
interface IRepo  
{  //...  
}  

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

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

And everything worked fine.

But now I delete the interface IRepoand do

@Stateless  
class Repo     {  // ..  
}  

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

and JNDI lookup is not performed.

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

Can I inject dependencies without an interface?

+3
source share
1 answer

You have to use

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

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

Make sure you are using an application server that supports EJB-3.1

+5
source

All Articles