使用RestEasy和JBoss 7.1进行JAX-RS bean验证不起作用

时间:2015-07-27 15:24:44

标签: web-services validation java-ee jboss resteasy

我想在JAX-RS网络服务中启用验证参数。我使用JavaEE 6RestEasy 3.0.6.FinalJBoss 7.1 Final作为Application Server。

我写了这个简单的WS:

@Path("/accounts")
public interface MyWS {

    @PUT
    @Path("/")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ValidateRequest
    public Response createUser(@Valid User request);

}

public class MyWsImpl implements MyWS {

    private static Logger LOG =  LogManager.getLogger(MyWsImpl.class);

    @Override
    public Response createUser(User request) {

    LOG.info("doing");
    return Response.status(200).build();

    }

}

public class User {

    @NotNull
    @Size(min=4, max=50)
    private String name;

    @NotNull
    private String surname;

...
}

执行请求时,服务器日志为:

17:21:05,324 INFO  [stdout] (http--0.0.0.0-8080-2) 17:21:05.324 [http--0.0.0.0-8080-2] DEBUG [RS-WS-Invoke] - PUT (/accounts) - 127.0.0.1

17:21:05,355 INFO  [stdout] (http--0.0.0.0-8080-2) annotation[0]: @javax.ws.rs.Path(value=/accounts)

17:21:05,373 INFO  [stdout] (http--0.0.0.0-8080-2) 17:21:05.373 [http--0.0.0.0-8080-2] INFO  it.prisma.businesslayer.bizws.paas.services.smsaas.MyWsImpl - doing

17:21:05,374 INFO  [stdout] (http--0.0.0.0-8080-2) declaring class: interface it.prisma.businesslayer.bizws.paas.services.smsaas.MyWS

17:21:05,374 INFO  [stdout] (http--0.0.0.0-8080-2) annotation[0]: @javax.ws.rs.Path(value=/accounts)

17:21:05,379 INFO  [stdout] (http--0.0.0.0-8080-2) 17:21:05.379 [http--0.0.0.0-8080-2] DEBUG [RS-WS-Invoke-Response] - PUT (/accounts) - 127.0.0.1 - RESPONSE[Status:400, Time:55ms]

但我希望ValidationException加注并且代码不会被执行。

出了什么问题?

由于

1 个答案:

答案 0 :(得分:0)

您是否启用了ValidationInterceptor?

collapsesLayers

tutorial link