我正在尝试使用如下所述的构造函数验证:
https://docs.oracle.com/javaee/7/tutorial/bean-validation003.htm
我有一个提供字符串的简单生产者字段......
public class GreetingProducer {
@Produces @Named("greeting")
private String greeting = "Ron";
}
...注入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);
}
}
在Wildfly 9上部署不会产生任何错误,并且调用servlet会打印Hello Ron
,尽管部署失败。我也尝试了不同的约束声明,但没有任何效果。
为什么验证不起作用的任何想法?