RestEasy @ValidateRequest无效

时间:2016-05-27 11:47:33

标签: jax-rs resteasy nhibernate-validator

I am having below configuration for a RestEasy Rest WS 

jaxrs-api-2.3.5.Final.jar,
resteasy-jaxrs-2.3.5.Final.jar,
resteasy-hibernatevalidator-provider-2.3.5.Final.jar,
hibernate-validator-4.3.2.Final.jar,
validation-api-1.0.0.GA.jar

I have added @ValidateRequest on class(tried on method as well) to validate any request input data before processing the request but i dont know why validation in not being invoked.

@Path(value = "/events") @ValidateRequest public class EventRestController {

@GET
@Produces({ MediaType.APPLICATION_XML, ACCEPT_HEADER })
public Response get(@QueryParam("componentSerialNumber") @NotNull String componentSerialNumber) {

    System.out.println("powerChangeEvevnt.getComponentSerialNumber()   " +   componentSerialNumber);

    return Response.ok().build();
}

}

我不知道我错过了什么。 请建议。

1 个答案:

答案 0 :(得分:0)

启用Rest资源和提供程序的自动扫描解决了问题,验证开始工作。

在web.xml中将resteasy.scan参数值设置为true

我已经在扩展javax.ws.rs.Application类的子类中显式注册了所有资源,但它没有将HibernateValidator视为验证的验证器。我发现将HibernateValidator注册为非常复杂的验证器,因此只需删除此显式注册的配置类并启用自动扫描。