问题描述
今天用spring整合了一下一个案例,可是在做spring配置的文件的时候报错了。网上搜了很多的方法也都试了可是还是不行,贴在这里大大们帮我看一下吧。applicationContext.xml,配置文件,放在/WEB-INF下了。<?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:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!--定义数据库datasource--><beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"><propertyname="driverClass"><value>com.mysql.jdbc.Driver</value></property><propertyname="jdbcUrl"><value>jdbc:mysql:///mypaimai</value></property><propertyname="user"><value>root</value></property><propertyname="password"><value>root123</value></property><propertyname="maxPoolSize"><value>80</value></property><propertyname="minPoolSize"><value>1</value></property><propertyname="initialPoolSize"><value>1</value></property><propertyname="maxIdleTime"><value>20</value></property></bean><!--定义数据库注入实体类--><beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><reflocal="dataSource"/></property><propertyname="mappingResources"><list><value>cn/com/emp/User.hbm.xml</value></list></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><propkey="show_sql">true</prop><propkey="hibernate.jdbc.batch_size">20</prop></props></property></bean><beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><propertyname="sessionFactory"ref="sessionFactory"/></bean><!--访问层--><beanid="userDaoImp"class="cn.com.dao.imp.UserDaoImp"><propertyname="transactionManager"><refbean="transactionManager"/></property></bean><!--action--><beanid="loginAction"class="cn.com.action.LoginAction"><propertyname="userDaoImp"><refbean="userDaoImp"/></property></bean></beans>
web.xml文件<?xmlversion="1.0"encoding="UTF-8"?><web-appversion="2.5"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_2_5.xsd"><display-name>SSHProject</display-name><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><welcome-file-list><welcome-file>login.jsp</welcome-file></welcome-file-list><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
报错内容:[code=text]十二月27,20147:04:16下午org.apache.catalina.core.StandardContextlistenerStartSEVERE:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userDaoImp'definedinServletContextresource[/WEB-INF/applicationContext.xml]:Errorsettingpropertyvalues;nestedexceptionisorg.springframework.beans.NotWritablePropertyException:Invalidproperty'transactionManager'ofbeanclass[cn.com.dao.imp.UserDaoImp]:Beanproperty'transactionManager'isnotwritableorhasaninvalidsettermethod.Doestheparametertypeofthesettermatchthereturntypeofthegetter?atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)atorg.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)atorg.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1621)atjava.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)atjava.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)atjava.util.concurrent.FutureTask.run(FutureTask.java:166)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)atjava.lang.Thread.run(Thread.java:722)Causedby:org.springframework.beans.NotWritablePropertyException:Invalidproperty'transactionManager'ofbeanclass[cn.com.dao.imp.UserDaoImp]:Beanproperty'transactionManager'isnotwritableorhasaninvalidsettermethod.Doestheparametertypeofthesettermatchthereturntypeofthegetter?atorg.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)atorg.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)atorg.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)atorg.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)...30more希望大家给点意见,拜谢
解决方案
解决方案二:
userDaoImp类中有transactionManager属性,并提供geter,setter方法了么
解决方案三:
引用1楼windbeside的回复:
userDaoImp类中有transactionManager属性,并提供geter,setter方法了么
transactionManager不是属性是id,这个应该没有问题哦
解决方案四:
大大们快点来啊,人工置顶
解决方案五:
userDaoImp的java文件和hbm文件贴出来看看是不是没有主键呀