问题描述
错误日志:严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'helloControllor':Injectionofautowireddependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatecom.qizweb.service.IUserServicecom.qizweb.controller.HelloControllor.userService;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userService':Injectionofautowireddependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatecom.qizweb.dao.IUserDAOcom.qizweb.service.impl.UserService.userDao;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userDao':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'definedinclasspathresource[config/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
解决方案
本帖最后由 siibb 于 2014-11-23 16:45:23 编辑
解决方案二:
atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)atorg.apache.catalina.core.StandardContext.start(StandardContext.java:4709)atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:583)atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)atorg.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)atorg.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)atorg.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)atorg.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)atorg.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)atorg.apache.catalina.core.StandardHost.start(StandardHost.java:822)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)atorg.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)atorg.apache.catalina.core.StandardService.start(StandardService.java:525)atorg.apache.catalina.core.StandardServer.start(StandardServer.java:754)atorg.apache.catalina.startup.Catalina.start(Catalina.java:595)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)Causedby:org.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatecom.qizweb.service.IUserServicecom.qizweb.controller.HelloControllor.userService;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userService':Injectionofautowireddependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatecom.qizweb.dao.IUserDAOcom.qizweb.service.impl.UserService.userDao;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userDao':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'definedinclasspathresource[config/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)...37moreCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userService':Injectionofautowireddependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatecom.qizweb.dao.IUserDAOcom.qizweb.service.impl.UserService.userDao;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userDao':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'definedinclasspathresource[config/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclass
解决方案三:
atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)...39moreCausedby:org.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatecom.qizweb.dao.IUserDAOcom.qizweb.service.impl.UserService.userDao;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userDao':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'definedinclasspathresource[config/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)...50moreCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userDao':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'definedinclasspathresource[config/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)...52moreCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'ht'definedinclasspathresource[config/applicationContext.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)atorg.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)...63moreCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[config/applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)...78more
解决方案四:
Causedby:java.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclassatjava.lang.ClassLoader.defineClass1(NativeMethod)atjava.lang.ClassLoader.defineClass(ClassLoader.java:621)atjava.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)atorg.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)atorg.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)atorg.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)atorg.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)atorg.hibernate.cfg.AnnotationConfiguration.createExtendedMappings(AnnotationConfiguration.java:187)atorg.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)atorg.hibernate.cfg.Configuration.buildMappings(Configuration.java:1307)atorg.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)atorg.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)...85more2014-11-2316:40:43org.apache.catalina.core.StandardContextstart严重:ErrorlistenerStart2014-11-2316:40:43org.apache.catalina.core.StandardContextstart严重:Context[/qizsysweb]startupfailedduetopreviouserrors2014-11-2316:40:43org.apache.catalina.core.ApplicationContextlog信息:ClosingSpringrootWebApplicationContext2014-11-2316:40:43org.apache.catalina.loader.WebappClassLoadercheckThreadLocalMapForLeaks严重:Thewebapplication[/qizsysweb]createdaThreadLocalwithkeyoftype[com.sun.faces.util.Util$1](value[com.sun.faces.util.Util$1@ada6d09])andavalueoftype[java.util.HashMap](value[{com.sun.faces.patternCache={=}}])butfailedtoremoveitwhenthewebapplicationwasstopped.Thisisverylikelytocreateamemoryleak.2014-11-2316:40:43org.apache.catalina.startup.HostConfigdeployDirectory信息:DeployingwebapplicationdirectoryROOT2014-11-2316:40:43org.apache.coyote.http11.Http11Protocolstart信息:StartingCoyoteHTTP/1.1onhttp-80802014-11-2316:40:43org.apache.jk.common.ChannelSocketinit信息:JK:ajp13listeningon/0.0.0.0:80092014-11-2316:40:43org.apache.jk.server.JkMainstart信息:JkrunningID=0time=0/19config=null2014-11-2316:40:43org.apache.catalina.startup.Catalinastart信息:Serverstartupin4225ms
解决方案五:
web.xml文件:<?xmlversion="1.0"encoding="UTF-8"?><web-appversion="3.0"xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name></display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:config/applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>spring-mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:config/spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>spring-mvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
解决方案六:
spring.mvc文件<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"default-lazy-init="true"><context:annotation-config/><!--使Spring支持自动检测组件,如注解的Controller--><context:component-scanbase-package="com.qizweb.controller"/><beanid="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"p:prefix="/WEB-INF"p:suffix=".jsp"/><beanclass="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/><!--启动SpringMVC的注解功能,完成请求和注解POJO的映射--><beanclass="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><propertyname="messageConverters"><list><beanclass="org.springframework.http.converter.StringHttpMessageConverter"></bean></list></property></bean></beans>applicationContext.xml:<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.1.xsd"><context:annotation-config/><!--扫描annotation类,过滤Service,Repository--><context:component-scanbase-package="com.qizweb"></context:component-scan><beanclass="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/><beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><propertyname="driverClassName"value="com.mysql.jdbc.Driver"></property><propertyname="url"value="jdbc:mysql://localhost:3306/qizweb"></property><propertyname="username"value="root"></property><propertyname="password"value="123"></property></bean><beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop></props></property><propertyname="annotatedClasses"><list><value>com.qizweb.entity.Books</value><value>com.qizweb.entity.User</value></list></property></bean><beanid="ht"class="org.springframework.orm.hibernate3.HibernateTemplate"><propertyname="sessionFactory"ref="sessionFactory"></property></bean><!--<beanid="BooksDAO"class="com.qizweb.dao.impl.BooksDAO"></bean><beanid="UserDAO"class="com.qizweb.dao.impl.UserDAO"></bean>--></beans>user.javapackagecom.qizweb.entity;importjava.util.HashSet;importjava.util.Set;importjavax.persistence.CascadeType;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.FetchType;importjavax.persistence.GeneratedValue;importstaticjavax.persistence.GenerationType.IDENTITY;importjavax.persistence.Id;importjavax.persistence.OneToMany;importjavax.persistence.Table;/***Userentity.@authorMyEclipsePersistenceTools*/@Entity@Table(name="user",catalog="qizweb")publicclassUserimplementsjava.io.Serializable{//FieldsprivateIntegerid;privateStringname;privateSet<Books>bookses=newHashSet<Books>(0);//Constructors/**defaultconstructor*/publicUser(){}/**fullconstructor*/publicUser(Stringname,Set<Books>bookses){this.name=name;this.bookses=bookses;}//Propertyaccessors@Id@GeneratedValue(strategy=IDENTITY)@Column(name="id",unique=true,nullable=false)publicIntegergetId(){returnthis.id;}publicvoidsetId(Integerid){this.id=id;}@Column(name="name",length=50)publicStringgetName(){returnthis.name;}publicvoidsetName(Stringname){this.name=name;}@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="user")publicSet<Books>getBookses(){returnthis.bookses;}publicvoidsetBookses(Set<Books>bookses){this.bookses=bookses;}}
解决方案七:
UserDAO@Component("userDao")publicclassUserDAOimplementsIUserDAO{privatestaticfinalLoggerlog=LoggerFactory.getLogger(UserDAO.class);@ResourceprivateHibernateTemplateht;//propertyconstantspublicstaticfinalStringNAME="name";protectedvoidinitDao(){//donothing}publicvoidsave(UsertransientInstance){log.debug("savingUserinstance");try{ht.save(transientInstance);log.debug("savesuccessful");}catch(RuntimeExceptionre){log.error("savefailed",re);throwre;}}....
解决方案八:
你的web.xml文件中的<listener>标签中的前面的空格去掉、都报listener、初始化失败了
解决方案九:
Causedby:java.lang.IncompatibleClassChangeError:classorg.hibernate.cfg.ExtendedMappingshasinterfaceorg.hibernate.cfg.Mappingsassuperclasshibernate的jar包冲突检查下hibernate相关jar中的Mappings是接口还是类?
解决方案十:
jar包冲突了吧,把hibernateannotation的包去掉试试