【问题标题】:@NotNull @QueryParam("String") String not working in jersey validations@NotNull @QueryParam("String") 字符串在球衣验证中不起作用
【发布时间】:2018-05-10 07:59:34
【问题描述】:

我正在尝试使用 javax.validation.validation-api 来验证 @QueryParam 参数。我是jersey的新手,所以不太了解,请查看下面的代码

代码:

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{services/SuperWeb}")
@ValidateOnExecution
public String getBranchName(@PathParam("name") String name,
    @NotNull @QueryParam("phone") String phone,
    @NotNull @QueryParam("email") String email) {

    try {
        //Some code where I should not check the phone and email is not null...
    } catch(Exception exception) { 
        throw new ...

    }
    return "";
} 

Pom.xml

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-bean-validation</artifactId>
    <version>2.12</version>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </exclusion>
    </exclusions>
</dependency>

【问题讨论】:

标签: java rest jersey


【解决方案1】:

您是否检查以确保您没有在 Jersey 配置中设置任何这些,在扩展 ResourceConfig 的类中。 如果是,那么请将其设为 false 以启用验证。你试一试 再次通过您的 web.xml 以获得更多帮助。

CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, 
ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE,
ServerProperties.BV_FEATURE_DISABLE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-23
    • 2017-05-19
    • 1970-01-01
    • 2020-10-04
    • 2015-11-28
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多