I'm starting to study EJB, and i'm having problems deploying my application.
I'm using JBoss as Application Server.
This is my Bean Interface:
public interface HelloWorldInterface {
public String printMessage();
}
This is my Bean (local):
@Local
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class LocalHelloWorld implements HelloWorldInterface{
/**
* Default constructor.
*/
public LocalHelloWorld() {
// TODO Auto-generated constructor stub
}
@Override
public String printMessage() {
return "This is a local EJB called \"LocalHelloWorld\"";
}
}
This is my servlet using it:
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB
private LocalHelloWorld localHelloWorld;
}
I get this error:
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'source.bean.LocalHelloWorld' for binding MyServlet/localHelloWorld at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
This error gets fixed if i use this:
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB (beanName="LocalHelloWorld")
private HelloWorldInteface localHelloWorld;
}
Why does this happen?
Thanks