问题描述
org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.hibernate.PropertyNotFoundException:Couldnotfindagetterforidinclasscom.wee.s2sh.entity.Useratorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:681)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)atorg.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)atjava.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)atjava.util.concurrent.FutureTask.run(FutureTask.java:262)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)atjava.lang.Thread.run(Thread.java:744)Causedby:org.hibernate.PropertyNotFoundException:Couldnotfindagetterforidinclasscom.wee.s2sh.entity.Useratorg.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:310)atorg.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:304)atorg.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:497)atorg.hibernate.tuple.PropertyFactory.buildIdentifierAttribute(PropertyFactory.java:87)atorg.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:163)atorg.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)atorg.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)atjava.lang.reflect.Constructor.newInstance(Constructor.java:526)atorg.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)atorg.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)atorg.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)atorg.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)atorg.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)...25morespring配置xml:<?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:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd"><!--加载数据库属性配置文件--><context:property-placeholderlocation="classpath:db.properties"/><!--数据库连接池c3p0配置--><beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"><propertyname="jdbcUrl"value="${db.url}"></property><propertyname="driverClass"value="${db.driverClassName}"></property><propertyname="user"value="${db.username}"></property><propertyname="password"value="${db.password}"></property><propertyname="maxPoolSize"value="40"></property><propertyname="minPoolSize"value="1"></property><propertyname="initialPoolSize"value="1"></property><propertyname="maxIdleTime"value="20"></property></bean><!--session工厂--><beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><propkey="hibernate.show_sql">true</prop></props></property><propertyname="mappingResources"><value>com/wee/s2sh/entity/User.hbm.xml</value></property></bean><!--配置事务管理器--><beanid="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><propertyname="sessionFactory"ref="sessionFactory"/></bean><beanid="baseDao"class="com.wee.s2sh.dao.impl.BaseDaoImpl"><propertyname="sessionFactory"ref="sessionFactory"></property></bean><beanid="userService"class="com.wee.s2sh.service.user.impl.UserServiceImpl"><propertyname="baseDao"ref="baseDao"></property></bean><beanid="Login"class="com.wee.s2sh.action.Login"><propertyname="userService"ref="userService"></property></bean><!--配置事务通知属性--><tx:adviceid="txAdvice"transaction-manager="transactionManager"><!--定义事务传播属性--><tx:attributes><tx:methodname="insert*"propagation="REQUIRED"/><tx:methodname="update*"propagation="REQUIRED"/><tx:methodname="edit*"propagation="REQUIRED"/><tx:methodname="save*"propagation="REQUIRED"/><tx:methodname="add*"propagation="REQUIRED"/><tx:methodname="new*"propagation="REQUIRED"/><tx:methodname="set*"propagation="REQUIRED"/><tx:methodname="remove*"propagation="REQUIRED"/><tx:methodname="delete*"propagation="REQUIRED"/><tx:methodname="change*"propagation="REQUIRED"/><tx:methodname="get*"propagation="REQUIRED"read-only="true"/><tx:methodname="find*"propagation="REQUIRED"read-only="true"/><tx:methodname="load*"propagation="REQUIRED"read-only="true"/><tx:methodname="*"propagation="REQUIRED"read-only="true"/></tx:attributes></tx:advice><!--应用普通类获取bean<beanid="appContext"class="com.soanl.util.tool.ApplicationUtil"/>--><!--配置事务切面--><aop:config><aop:pointcutid="serviceOperation"expression="execution(*com.wee.s2sh.service..*.*(..))"/><aop:advisoradvice-ref="txAdvice"pointcut-ref="serviceOperation"/></aop:config><!--自动加载构建bean--><!--<context:component-scanbase-package="com.wee.s2sh.entity"/>--></beans>
解决方案
解决方案二:
User对象的id有没有get方法?