yinbingqiu 2016-12-18 06:12 采纳率: 0%
浏览 1324

springmvc配置表单校验jar包依赖报错

我最近在配置springmvc校验的时候出现了问题,我猜测主要是依赖的问题希望大家帮帮忙。接下来我贴出我的配置
tomcat8+jdk8+spring版本4.3.3.RELEASE

最重要的部分引入校验依赖

 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.2.2.Final</version>
        </dependency>
        <!-- 在校验文件中使用el表达式 --> 
        <dependency>  
            <groupId>javax.el</groupId>  
            <artifactId>javax.el-api</artifactId>  
            <version>2.2.4</version>  
            <scope>provided</scope>  
        </dependency>  
    ![图片说明](https://img-ask.csdn.net/upload/201612/18/1482041265_781261.png)
    下面是springmvc.xml里面的配置(其实这个配置应该是没有错的,因为这个配置就算没有报的错也是一样的)
 <!-- spring mvc验证开始 ,若不使用这种配置,需要将错误信息硬编码到代码里,不易修改-->
    <!-- 以下 validator  ConversionService 在使用 mvc:annotation-driven 会 自动注册-->  
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">  
        <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>  
        <!-- 如果不加默认到 使用classpath下的 ValidationMessages.properties -->  
        <property name="validationMessageSource" ref="messageSource"/>  
    </bean>  

    <!-- 国际化的消息资源文件(本系统中主要用于显示/错误消息定制) -->  
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">  
        <property name="basenames">  
            <list>  
                <!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找  -->  
                <value>classpath:validation.properties</value>  
                <value>classpath:org/hibernate/validator/ValidationMessages</value>  
            </list>  
        </property>  
        <property name="useCodeAsDefaultMessage" value="false"/>  
        <property name="defaultEncoding" value="UTF-8"/>  
        <property name="cacheSeconds" value="60"/>  
    </bean>  
    <!-- spring mvc验证结束 -->

接下来是报错信息(我给剪切到一行了)

这里是主要信息

 Caused by: org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name '(inner bean)#132070ce':
 Cannot resolve reference to bean 'validator' while setting bean property 'validator'; 
 nested exception is org.springframework.beans.factory.BeanCreationException: 
 Error creating bean with name 'validator' defined in URL 
 [file:/E:/Workspaces/Web%20Templet/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/web_homework/WEB-INF/classes/springmvc.xml]:
 Invocation of init method failed; nested exception is java.lang.ClassFormatError: 
 Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence

这里是详细的错误信息

 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.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1140)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1027)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5038)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5348)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2558)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:859)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1302)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.hibernate.validator.internal.util.privilegedactions.LoadClass.loadNonValidatorClass(LoadClass.java:103)
    at org.hibernate.validator.internal.util.privilegedactions.LoadClass.run(LoadClass.java:64)
    at org.hibernate.validator.internal.util.privilegedactions.LoadClass.run(LoadClass.java:29)
    at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.run(DefaultTraversableResolver.java:147)
    at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.detectJPA(DefaultTraversableResolver.java:67)
    at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.<init>(DefaultTraversableResolver.java:57)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:126)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:96)
    at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:31)
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)
    at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:248)
    at org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
    ... 28 more

希望大家帮帮忙,查询了很多网上的解决办法但是我的配置都和他们说的是一样的但是就是存在这样的问题,自己的能力实在解决不了。只能猜测是jar包依赖的问题但是包又都是全的,所以没有拌饭解决了。

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2016-12-31 09:50
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀