【问题标题】:RestEasy @ValidateRequest is not workingRestEasy @ValidateRequest 不起作用
【发布时间】:2016-05-27 11:47:32
【问题描述】:
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 公共类 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();
}

}

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

【问题讨论】:

    标签: jax-rs resteasy nhibernate-validator


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2011-02-10
      • 2011-12-08
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      相关资源
      最近更新 更多