2013-06-22 107 views
0

我的問題與Maven連接到Spring和Hibernate。我創建了一個應用程序,我無法運行它。我已經找到了彌散的原因,爲什麼它可能發生,但我不可能解決它。 這是我的錯誤信息:Spring框架休眠豆

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/our-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.VerifyError: class org.hibernate.type.WrappedMaterializedBlobType overrides final method getReturnedClass.()Ljava/lang/Class; 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:657) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1637) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.VerifyError: class org.hibernate.type.WrappedMaterializedBlobType overrides final method getReturnedClass.()Ljava/lang/Class; 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141) 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104) 
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:818) 
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:549) 
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) 
    ... 26 more 
Caused by: java.lang.VerifyError: class org.hibernate.type.WrappedMaterializedBlobType overrides final method getReturnedClass.()Ljava/lang/Class; 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(Unknown Source) 
    at java.security.SecureClassLoader.defineClass(Unknown Source) 
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904) 
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
    at org.hibernate.type.BasicTypeRegistry.<init>(BasicTypeRegistry.java:91) 
    at org.hibernate.type.TypeResolver.<init>(TypeResolver.java:59) 
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:250) 
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:302) 
    at org.hibernate.cfg.AnnotationConfiguration.<init>(AnnotationConfiguration.java:168) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) 
    ... 32 more 

我已經囊括了所有hibarnate罐子,pom.xml文件也是正確的。什麼是驚奇我的朋友可以在他的配置上運行我的應用程序。

編輯: 我試圖刪除休眠的註解罐子但在那之後我看到這個錯誤:

15:56:48,325 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.s[email protected]c06f9a: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,jspViewResolver,messageSource,propertyConfigurer,dataSource,sessionFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.core.session.SessionRegistryImpl#0,org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.config.http.UserDetailsServiceInjectionBeanPostProcessor#0,org.springframework.security.filterChainProxy,org.springframework.security.provisioning.JdbcUserDetailsManager#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager]; root of factory hierarchy 
cze 22, 2013 3:56:48 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/our-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class [ app.our.entity.Company] declared in Hibernate configuration <mapping/> entry 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:657) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1637) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: org.hibernate.MappingException: Unable to load class [ app.our.entity.Company] declared in Hibernate configuration <mapping/> entry 
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2369) 
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2310) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2290) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:242) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:71) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2243) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:230) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:71) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2194) 
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:218) 
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:71) 
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:642) 
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) 
    ... 26 more 
Caused by: java.lang.ClassNotFoundException: app.our.entity.Company 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:188) 
    at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) 
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2366) 
    ... 40 more 

15:56:48,340 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/our-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class [ app.our.entity.Company] declared in Hibernate configuration <mapping/> entry 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:657) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1637) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: org.hibernate.MappingException: Unable to load class [ app.our.entity.Company] declared in Hibernate configuration <mapping/> entry 
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2369) 
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2310) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2290) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:242) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:71) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2243) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:230) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:71) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2194) 
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:218) 
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:71) 
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:642) 
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) 
    ... 26 more 
Caused by: java.lang.ClassNotFoundException: app.our.entity.Company 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:188) 
    at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) 
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2366) 
    ... 40 more 
+0

是否更改休眠版本?嘗試做一個'mvn clean'。您的應用程序中可能有多個版本的JAR。 –

+0

我使用Maven庫,並且有所有必需的jar:annotations-3.5.6.Final,core-3.6.7.Final,jpa-2.0-api.1.0.1Final,commons-annotations-3.2.0.Final。 –

+0

根據https://forum.hibernate.org/viewtopic.php?p=2442832,您可能想嘗試刪除註釋-3.5.6.Final。 –

回答

0

它看起來像你有你的類路徑中休眠的多個版本。這個錯誤的根源是

Caused by: java.lang.VerifyError: class org.hibernate.type.WrappedMaterializedBlobType overrides final method getReturnedClass.()Ljava/lang/Class; 

我的猜測是版本之間略有變化的API和您的應用程序加載休眠的錯誤版本(可能通過短暫的依賴)。它可能適用於朋友的配置,因爲這些類恰好按照正確的順序加載。

驗證是否包含多個版本,如果是,請嘗試刪除重複(或至少強制pom的dependencyManagement部分中的正確版本)。

1

當你在你的Maven的依賴(JAR版本不匹配)加入罐的多個版本,它發生,所以請檢查here