org.springframework.beans.factory.BeanCreationException

项目场景:

import lombok.Data;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
public class Account {
    @NotEmpty(message = "用户名不能为空")
    private String username;
    @Size(min = 6,max = 20,message = "密码长度为6-20位")
    private String password;
    @Email(regexp = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\\\\\\\.[a-zA-Z0-9-]+)*\\\\\\\\.[a-zA-Z0-9]{2,6}$",message = "请输入正确的邮箱")
    private String email;
    @Pattern(regexp = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\\\\\\\\\\\\\\\d{8}$",message = "请输入正确的电话格式")
    private String phone;
}
@Controller
@RequestMapping("/validate")
public class ValidateHandler {

    @GetMapping("/register")
    public String register(Model model){
        model.addAttribute(new Account());
        return "register";
    }

    @PostMapping("/register")
    public String register(@Valid Account account,BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            return "register";
        }
        return "success";
    }
}
<%--
  Created by IntelliJ IDEA.
  User: southwind
  Date: 2020-02-13
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


    Title


    

用户注册

用户名:
密码:
邮箱:
电话:

问题描述

org.springframework.beans.factory.BeanCreationException_第1张图片

org.springframework.beans.factory.BeanCreationException_第2张图片

这个是敲数据校验代码的时候出现的错误,使用的是JSR-303数据检验组件,代码敲完就报错了。


原因分析:

网上查阅了很多资料无果,我觉得可能是组件版本过高导致,就试试把jboss-logging版本调低了,结果发现代码可以运行了。(JSR303版本如下)


解决方案:


    
      org.hibernate
      hibernate-validator
      5.3.6.Final
    
    
      javax.validation
      validation-api
      2.0.1.Final
    
    
      org.jboss.logging
      jboss-logging
      3.4.1.Final
    

你可能感兴趣的:(java,maven,spring,mvc)