关于spring整合struts2+hibernate的一个配置文件问题

问题描述

今天用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文件贴出来看看是不是没有主键呀

时间: 2024-09-17 03:59:48

关于spring整合struts2+hibernate的一个配置文件问题的相关文章

spring整合struts2怎样配置有多个result的action?

问题描述 spring整合struts2怎样配置有多个result的action? struts.xml中的配置 <action name="User_*" class="userAction" method="{1}"> <result name="list">/list.jsp</result> <result name="save">/save.jsp&

SSH2-&amp;gt;Spring Framework2 struts2 hibernate

Spring Framework 3.0:http://www.springsource.com/download/community struts2 hibernate

重新学习之spring第四个程序,整合struts2+hibernate+spring

第一步:导入三大框架的jar包(struts2.3.16.1+hibernate3.2+spring3.2.4)   第二步:编写web.xml 和struts.xml和applicationContext.xml和applicationContext-service.xml和application-actionContext.xml和applicationContext-dao.xml web.xml 1 <?xml version="1.0" encoding="U

Spring整合了CXF的一个applicationContext.xml的配置文件

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:jaxws="http://cxf.apache.org/

spring整合hibernate-springMVC+hibernate+freemarker有没有完整的项目?

问题描述 springMVC+hibernate+freemarker有没有完整的项目? springMVC+hibernate+freemarker有没有完整的项目??大神们...求助...... 解决方案 http://download.csdn.net/detail/zhao_zhengzz/9347211

新手疑问:一个关于sping整合struts2的奇怪问题

问题描述 今天实验了下spring整合struts2,发现个奇怪的问题:实体类有Vet,Owner,Visits...在action中,是这样写的:privateVetvet;privateOwnerowner;当用struts2自己管理action时,没有任何问题当把action交给spring管理时,action中的实体vet对象始终为null,不管是哪个action,只要用到了实体vet,都是null,而其他的实体对象,如owner却啥问题没有.后来把privateVetVet;改成pri

mvc-spring整合struts2的优点

问题描述 spring整合struts2的优点 spring有自己的mvc,为什么现在还是有很多公司选择spring整合struts2 解决方案 现在的很多公司由于用的struts早,所以会用struts,但是公司和公司是不一样的,有的公司也用struts,struts更加符合oop思想

java-测试Spring整合hibernate/Struts2框架时,配置文件报奇怪的错误,求解

问题描述 测试Spring整合hibernate/Struts2框架时,配置文件报奇怪的错误,求解 为什么会报无法识别property? 解决方案 怎么都是这种问题,property要包含在bean标签内 解决方案二: Struts2+hibernate+spring整合时错误Struts2+hibernate+spring整合时错误 解决方案三: http://iteye.blog.163.com/blog/static/186308096201210265334689/ 解决方案四: pro

hibernate 如何将所有sql语句整合到一个配置文件

问题描述 各位知道如何将hibernate 的sql放到一个配置文件中然后加载配置文件,通过key的到sql,增加可维护性 问题补充:放到一个文件中增加可维护性和可重用性,以后如果改的话就可以直接编辑配置文件了,避免修改class,那多麻烦啊 解决方案 如果是想把所有表的sql查询都放一起的话,参考这个http://hzhlu.iteye.com/blog/769019只是使用formula的话,参考这个http://blog.csdn.net/sooneasy/article/details/