I'm trying to use constructor validation as described here:
https://docs.oracle.com/javaee/7/tutorial/bean-validation003.htm
I have a simple producer field that provides a string...
public class GreetingProducer {
@Produces @Named("greeting")
private String greeting = "Ron";
}
... which is injected into a servlet:
@WebServlet(urlPatterns = "/test")
@SuppressWarnings("serial")
public class TestServlet extends HttpServlet {
private final String greeting;
@Inject
public TestServlet(@Named("greeting") @Size(min = 4) String greeting) {
this.greeting = greeting;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("Hello " + greeting);
}
}
Deployment on Wildfly 9 doesn't yield any errors and calling the servlet prints Hello Ron
, although the deployment should fail. I also tried different flavours of constraint declaration but nothing worked.
Any ideas why the validation doesn't kick in?