0

我正在使用 Spring Integration 接收 http 消息,然后将其放入通道并进行一些转换。

我阅读了文档(https://docs.spring.io/spring-integration/reference/html/http.html),它看起来像:

@Bean
public HttpRequestHandlingMessagingGateway inbound() {
    HttpRequestHandlingMessagingGateway gateway =
        new HttpRequestHandlingMessagingGateway(true);
    gateway.setRequestMapping(mapping());
    gateway.setRequestPayloadType(SomeBean.class);
    gateway.setRequestChannelName("httpRequest");
    return gateway;
}

我想使用 JSR 303 bean 验证 ( https://beanvalidation.org/1.0/spec/ ) 来验证有效负载,这可能吗?什么是最好的方法?

提前致谢!

4

1 回答 1

0

有一个关于验证的专门段落:https ://docs.spring.io/spring-integration/reference/html/http.html#http-validation 。所以,你只需要使用setValidator()那个网关:

/**

 * Specify a {@link Validator} to validate a converted payload from request.

 * @param validator the {@link Validator} to use.

 * @since 5.2

 */

public void setValidator(Validator validator) {

    this.validator = validator;

}

验证 API 来自 Spring Framework:https ://docs.spring.io/spring/docs/5.2.4.RELEASE/spring-framework-reference/core.html#validation

于 2020-03-11T01:07:27.450 回答