Spring错误集(一)

在使用JSR303 validator时出现的错误.
环境配置: JDK8、Tomcat 7.

错误

type Exception report
message java.lang.NoClassDefFoundError: javax/el/ELResolver
description The server encountered an internal error that prevented it from fulfilling this request.

exception
Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0
.....
javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver

在springMVC上使用Hiberntae Validator,运行Tomcat时出现了上述的错误
解决方法:
使用Tomcat 8,不要使用Tomcat 7.
我的project的部分配置如下:
1. pom.xml的部分


        <dependency>
            <groupId>javax.validationgroupId>
            <artifactId>validation-apiartifactId>
            <version>2.0.1.Finalversion>
        dependency>
        <dependency>
            <groupId>org.hibernate.validatorgroupId>
            <artifactId>hibernate-validatorartifactId>
            <version>6.0.7.Finalversion>
        dependency>
        <dependency>
            <groupId>javax.elgroupId>
            <artifactId>javax.el-apiartifactId>
            <version>3.0.0version>
            <scope>providedscope>
        dependency>
  1. springMVC-servlet.xml部分
<mvc:annotation-driven validator="validator"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
        <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
        <property name="validationMessageSource" ref="messageSource"/>
bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        
        <property name="basenames" value="messages.message"/>
        
        <property name="useCodeAsDefaultMessage" value="true"/>
bean>

你可能感兴趣的:(Spring)