I'm trying to use Bean Validation with Jersey 2.0. When the submitted input is invalid I'm receiving a strange exception:
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)
(...)
My resource method looks like this:
@PUT
public Response createSchedule(@BeanParam @Valid Schedule schedule) {
(...)
In the bean class I use only one annotation constraint
@NotEmpty
protected String name;
...and the 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);
}
}
I would like to display a JSON formatted error message.
The issue was an incorrect version on jersey-bean-validation
. The library version was higher than my Jersey.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.