복붙노트

[SPRING] hibernate-validator의 예외. 상자의 예외는 java.lang.NoClassDefFoundError입니다 : ConfigurationImpl

SPRING

hibernate-validator의 예외. 상자의 예외는 java.lang.NoClassDefFoundError입니다 : ConfigurationImpl

나는 Spring에서 javax-validation과 hibaernate-validator를 사용하여 폼 검증을하고있다. 스프링에 필요한 기본 JAR 파일 이외.

나는 다음을 포함시켰다.

나는 spl4j 버전이 또한 걱정 스럽다는 것을 읽었습니다. 그래서 나는 또한 말하고 있습니다 :

###slf4j-api-1.7.5###
###slf4j-simple-1.7.5###
###log4j-1.2.17###

slf4j 및 log4j 호환성으로 인해 오류의 원인이 될 수 있습니까?

주석 기반 유효성 검사를 사용합니다.

몇 가지 코드를 제공하겠습니다.

import java.util.Date;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;


public class Customer {

    @Size(min=2, max=30)
    @NotEmpty
    private String name;

    @NotEmpty @Email
    private String email;

    @NotNull @Min(18) @Max(100)
    private Integer age;
public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

}
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    @Qualifier("messageSource")
    private MessageSource messageSource;

    @RequestMapping(value = "", method = RequestMethod.POST)
    public @ResponseBody List<String> saveCustomerAction(
             @Valid @ModelAttribute("customer") Customer customer,
            BindingResult bindingResult, Model model) {
         List<String> errorLog = new ArrayList<String>();
        if (bindingResult.hasErrors()) {
     errorLog.add("Error");

                }
            }
            return errorLog;
        }

        errorLog.add("No Error");
        return errorLog;
    }
}
type Exception report

   message Servlet.init() for servlet spring-rest threw exception

   description The server encountered an internal error that prevented it from fulfilling this request.

   exception

   javax.servlet.ServletException: Servlet.init() for servlet spring-rest threw exception
       org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
       org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
       org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
       org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
       org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
       org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
       java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
       org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
       java.lang.Thread.run(Thread.java:745)

###----###
###root cause###

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
        org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
        org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
        org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
        org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
        org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
        org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
        org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
        org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
        org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
        org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
        org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
        javax.servlet.GenericServlet.init(GenericServlet.java:158)
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        java.lang.Thread.run(Thread.java:745)

해결법

  1. ==============================

    1.이것은 Hibernate Validator FAQ에있는 것과 같습니다.

    이것은 Hibernate Validator FAQ에있는 것과 같습니다.

    Hibernate Validator 3, 4, 5의 차이점은 무엇입니까?

    Hibernate Validator 3.x와 4.x / 5.x는 다른 코드베이스이다.

    Hibernate Validator는 Hibernate 팀의 최초의 검증 프레임 워크이며, 이제는 "Legacy Hibernate Validator"라고 불린다. Hibernate Validator 4.x는 Bean Validation 1.0 (JSR 303)의 레퍼런스 구현이며, Hibernate Validator 5.x는 Bean Validation 1.1 (JSR 349)의 레퍼런스 구현이다. 액티브 개발은 5.x 코드베이스에서 발생합니다.

    또한 MVC 용 스프링 유효성 검사 프레임 워크를 사용하는 경우 :

     <!-- JSR-303 support will be detected on classpath and enabled automatically -->
     <mvc:annotation-driven />
    

    따라서 hibernate-validator-5.x는 JSR303을 지원하지 않을 것입니다. 버전을 4.x로 다운 그레이드하십시오.

    또한 Hibernate Validator 4.3.1을 선호합니다. 최종. 둘 다 서로 다른 패키지 구조를 가지고 있으므로 4.2.x가 아닙니다.

  2. from https://stackoverflow.com/questions/24957513/exception-in-hibernate-validator-nested-exception-is-java-lang-noclassdeffounde by cc-by-sa and MIT license