Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试将Bean验证API与Spring MVC集成时运行时服务器启动错误_Spring_Hibernate_Spring Mvc - Fatal编程技术网

尝试将Bean验证API与Spring MVC集成时运行时服务器启动错误

尝试将Bean验证API与Spring MVC集成时运行时服务器启动错误,spring,hibernate,spring-mvc,Spring,Hibernate,Spring Mvc,我正在尝试将Bean验证API-javax.Validation和hibernate验证程序与SpringMVC应用程序集成。我可以看出,当REST控制器方法不使用BindingResult参数时,服务器会正常启动并正常工作。但是,当我在函数签名中使用BindingResult arg时,我会看到如下运行时错误 SEVERE: The following errors and warnings have been detected with resource and/or provider cl

我正在尝试将Bean验证API-javax.Validation和hibernate验证程序与SpringMVC应用程序集成。我可以看出,当REST控制器方法不使用BindingResult参数时,服务器会正常启动并正常工作。但是,当我在函数签名中使用BindingResult arg时,我会看到如下运行时错误

SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.gigsky.usermanagement.restapi.api.UserManagement.createUsers(com.gigsky.usermanagement.restapi.beans.UsersList,org.springframework.validation.BindingResult) throws java.lang.Exception at parameter at index 0
  SEVERE: Method, public javax.ws.rs.core.Response com.gigsky.usermanagement.restapi.api.UserManagement.createUsers(com.gigsky.usermanagement.restapi.beans.UsersList,org.springframework.validation.BindingResult) throws java.lang.Exception, annotated with POST of resource, class com.gigsky.usermanagement.restapi.api.UserManagement, is not recognized as valid resource method.
Oct 8, 2015 11:34:44 PM com.sun.jersey.spi.spring.container.servlet.SpringServlet initiate
SEVERE: Exception occurred when intialization
代码:

控制器方法:

@POST
    @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
    @Consumes(MediaType.APPLICATION_JSON + ";charset=UTF-8")
    public Response createUsers(@Valid UsersList usersList, BindingResult result) throws Exception {
        if(result.hasErrors()){
            System.out.println("Error");
        }
        else{
            System.out.println("Success");
        }
        userManagementService.createUsers(usersList);
        return Response.status(Response.Status.OK).build();
    }
pom.xml

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.0.1.Final</version>
        </dependency>

org.hibernate
休眠验证器
5.0.1.最终版本
上面的依赖关系将依次拉动javax.validation:validatior api

UsersList本质上是以下UserInfo的列表

public class UserInfo {
    @JsonProperty
    private String type = "User";
    @JsonProperty
    private String userId;
    @JsonProperty
    @NotNull
    private String firstName;
    @JsonProperty
    private String lastName;
    @JsonProperty
    private String emailId;
    @JsonProperty
    private String password;
    @JsonProperty
    private String location;
    @JsonProperty
    private Address address;
    @JsonProperty
    private String preferredCurrency;
    @JsonProperty
    private String userStatus;
    @JsonProperty
    private String passwordSet;
    @JsonProperty
    private String createdOn;
    @JsonProperty
    private String homePhone;
    @JsonProperty
    private String mobile;
    @JsonProperty
    private String department;
    @JsonProperty
    private List<UserAccountAssociation> list;
公共类用户信息{
@JsonProperty
私有字符串type=“User”;
@JsonProperty
私有字符串用户标识;
@JsonProperty
@NotNull
私有字符串名;
@JsonProperty
私有字符串lastName;
@JsonProperty
私有字符串emailId;
@JsonProperty
私有字符串密码;
@JsonProperty
私有字符串位置;
@JsonProperty
私人地址;
@JsonProperty
私有字符串首选货币;
@JsonProperty
私有字符串用户状态;
@JsonProperty
私有字符串密码集;
@JsonProperty
私有字符串createdOn;
@JsonProperty
私人电话;
@JsonProperty
私有字符串移动;
@JsonProperty
私人弦乐部;
@JsonProperty
私人名单;
。。。。。
}

将web.xml中的SpringServlet更改为DispatcherServlet有助于我解决此问题。

您也可以粘贴您的模型用户吗?我已经将其粘贴到了Albert的上方,并且在您的请求中,您是否为firstname发送空值?是的,我根本不发送firstname字段。