You have to add beans.xml
file to WEB-INF. Now You have bean.xml
file.
In ProduceFormalGreeting
u have to use javax.enterprise.inject.Produces
(not javax.ws.rs.Produces
)
Vra
I am following a simple Java EE 6 annotations video on youtube. I have created a repo on github. There is a servlet to start with that creates a greeting string using annotation.
@WebServlet(urlPatterns = {"/HelloServlet"})
public class HelloServlet extends HttpServlet {
@Inject @Formal
String greetingMessage;
...
}
The formal qualifier is defined as follows:
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface Formal {}
And the producer is:
public class ProduceFormalGreeting {
@Produces
@Formal
public String GetFormalGreeting(){
return "Good morning !";
}
}
At compile time I get the following message from NetBeans:
Unsatisfied Dependency: No bean matches the inject point
At runtime, the string is null
in the servlet.
Oplossing
You have to add beans.xml
file to WEB-INF. Now You have bean.xml
file.
In ProduceFormalGreeting
u have to use javax.enterprise.inject.Produces
(not javax.ws.rs.Produces
)