我试图在Jersey 2.0中使用Bean Validation。当提交的输入无效时,我收到一个奇怪的例外:
SEVERE: Servlet.service() for servlet [API] in context with path [/API] threw exception [org.glassfish.jersey.server.internal.process.MappableException: java.lang.NoClassDefFoundError: org/glassfish/jersey/message/MessageUtils] with root cause
java.lang.ClassNotFoundException: org.glassfish.jersey.message.MessageUtils
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.glassfish.jersey.server.validation.internal.ValidationErrorMessageBodyWriter.writeTo(ValidationErrorMessageBodyWriter.java:162)
(...)
我的资源方法如下:
@PUT
public Response createSchedule(@BeanParam @Valid Schedule schedule) {
(...)
在bean类中,我只使用一个注释约束
@NotEmpty
protected String name;
...和ResourceConfig
:
public class Application extends ResourceConfig {
public Application() {
super();
packages( "com.test.api.resource" );
register(MustacheMvcFeature.class);
register(ResponseBodyWriter.class);
property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true);
}
}
我想显示JSON格式的错误消息。
答案 0 :(得分:0)
问题是jersey-bean-validation
上的版本不正确。图书馆版本高于我的泽西岛。