ibatis和Spring整合抛org.springframework.beans.factory.BeanCreationException

问题描述

『spring2.5和Ibatis2整合』spring配置文件如下:<?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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><propertyname="driverClassName"value="jdbc:sqlserver://localhost:1433;databaseName=Employ"></property><propertyname="url"value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property><propertyname="username"value="sa"></property><propertyname="password"value="123"></property></bean><!--根据dataSource和configLocation创建一个SqlMapClient--><!--org.springframework.orm.ibatis.SqlMapClientFactoryBean--><beanid="sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><propertyname="configLocation"value="configfile/sql-map-config.xml"/><propertyname="dataSource"ref="dataSource"></property></bean><!--根据sqlMapClien创建一个SqlMapClient模版类--><beanid="sqlMapClientTemplate"class="org.springframework.orm.ibatis.SqlMapClientTemplate"><propertyname="sqlMapClient"><refbean="sqlMapClient"/></property></bean><!--将上面的模版类织入到我们的DAO对象中--><beanid="employDao"class="dao.MpsTestDaoImpl"><propertyname="sqlMapClientTemplate"><refbean="sqlMapClientTemplate"/></property></bean></beans>在applicationContext.xml文件中不知道怎么配,我初次自学ibatis望大虾赐教错误详细信息如下:Errorcreatingbeanwithname'sqlMapClient'definedinclasspathresource[applicationContext.xml]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.NoSuchMethodError:com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)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:423)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)attest.Test.main(Test.java:19)Causedby:java.lang.NoSuchMethodError:com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;atorg.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:339)atorg.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertiesSet(SqlMapClientFactoryBean.java:292)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)...15more

解决方案

解决方案二:
引用楼主huzhongming12345的回复:

<!--根据sqlMapClien创建一个SqlMapClient模版类--><beanid="sqlMapClientTemplate"class="org.springframework.orm.ibatis.SqlMapClientTemplate"><propertyname="sqlMapClient"><refbean="sqlMapClient"/></property></bean><!--将上面的模版类织入到我们的DAO对象中--><beanid="employDao"class="dao.MpsTestDaoImpl"><propertyname="sqlMapClientTemplate"><refbean="sqlMapClientTemplate"/></property></bean>

把sqlMapClientTemplate删了DAO直接注入sqlMapClient就行了<beanid="employDao"class="dao.MpsTestDaoImpl"><propertyname="sqlMapClientTemplate"><refbean="sqlMapClient"/></property></bean>
解决方案三:
改了还是一样的错<!--根据dataSource和configLocation创建一个SqlMapClient--><!--org.springframework.orm.ibatis.SqlMapClientFactoryBean--><beanid="sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><propertyname="configLocation"value="configfile/sql-map-config.xml"/><propertyname="dataSource"ref="dataSource"></property></bean>报的就是这段的异常,反正是读取并解析spring这个配置文件有问题,我硬是没试出来,不知道错在哪个细节上呵呵~~
解决方案四:
看你的写法,还要手写DAO,请参考一下:myBatis3的使用-结合spring3(http://www.yulei.name/?p=413)。不需要手写DAO即可实现。如果要完整的配置文件样例,可以找我要。
解决方案五:
<propertyname="configLocation"value="configfile/sql-map-config.xml"/>你把sql-map-config.xml和spring配置文件放到一起并且把sql-map-config.xml代码贴出来下
解决方案六:
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)attest.Test.main(Test.java:19)Causedby:java.lang.NoSuchMethodError:com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;atorg.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:339)请确定红色标记处的文件
解决方案七:
初始化sqlMapClient时候出错。你看看,是否配置对了。
解决方案八:
引用4楼ashutc的回复:

<propertyname="configLocation"value="configfile/sql-map-config.xml"/>你把sql-map-config.xml和spring配置文件放到一起并且把sql-map-config.xml代码贴出来下

sql-map-config.xml配置如下:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEsqlMapConfigPUBLIC"-//ibatis.apache.org//DTDSQLMapConfig2.0//EN""http://ibatis.apache.org/dtd/sql-map-config-2.dtd"><sqlMapConfig><sqlMapresource="cofigfile/MpsTest.xml"/></sqlMapConfig>MpsTest.xml配置如下:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEsqlMapPUBLIC"-//ibatis.apache.org//DTDSQLMap2.0//EN""http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMapnamespace="MpsTest"><typeAliasalias="mploy"type="test.Employ"/><resultMapid="EmployResult"class="Employ"><resultproperty="id"column="id"/><resultproperty="enployName"column="enployName"/><resultproperty="salary"column="salary"/></resultMap><!--SelectwithnoparametersusingtheresultmapforAccountclass.--><selectid="selectAllEmploy"resultMap="EmployResult"><![CDATA[select*fromEmploy]]></select><!--Asimplerselectexamplewithouttheresultmap.Notethealiasestomatchthepropertiesofthetargetresultclass.--><!--Insertexample,usingtheAccountparameterclass--><insertid="insertEmploy"parameterClass="Employ"><![CDATA[insertintoEmploy(enployName,salary)values(#enployName#,#salary#)]]></insert><!--Updateexample,usingtheAccountparameterclass--><updateid="updateEmploy"parameterClass="Employ"><![CDATA[updateEmploysetenployName=#enployName#,salary=#salary#whereid=#id#]]></update><!--Deleteexample,usinganintegerastheparameterclass--><deleteid="deleteEmploy"parameterClass="java.lang.Integer"><![CDATA[deletefromEmploywhereid=#id#]]></delete></sqlMap>
解决方案九:
肯定是配置时候出错,不用说的……
解决方案十:
我也知道但我是初次自学ibatis吗关键是错在哪呢
解决方案十一:
propertyname="configLocation"value="configfile/sql-map-config.xml"/>说明configfile下有sql-map-config.xml但你的sql-map-config.xml里面<sqlMapConfig><sqlMapresource="cofigfile/MpsTest.xml"/></sqlMapConfig>那么你的MpsTest.xml在configfile/configfile下??
解决方案十二:
把那俩配置文件都按照格式发出来好吧?连web.xml也一起。
解决方案十三:
/***BuildaSqlMapClientinstancebasedonthegivenstandardconfiguration.*<p>ThedefaultimplementationusesthestandardiBATIS{@linkSqlMapClientBuilder}*APItobuildaSqlMapClientinstancebasedonanInputStream(ifpossible,*oniBATIS2.3andhigher)oronaReader(oniBATISuptoversion2.2).*@paramconfigLocationstheconfigfilestoloadfrom*@parampropertiestheSqlMapClientproperties(ifany)*@returntheSqlMapClientinstance(never<code>null</code>)*@throwsIOExceptionifloadingtheconfigfilefailed*@seecom.ibatis.sqlmap.client.SqlMapClientBuilder#buildSqlMapClient*/

时间: 2024-10-23 08:49:02

ibatis和Spring整合抛org.springframework.beans.factory.BeanCreationException的相关文章

ssh整合出错:org.springframework.beans.factory.BeanCreationException: Error creating

问题描述 applicationContent.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:context="http://w

急死人了,SSH整合报错,高手进来帮忙解决啊,org.springframework.beans.factory.BeanCreationException

问题描述 2010-11-13 12:37:39 org.apache.catalina.core.AprLifecycleListener init信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:InstalledMyEclipsebin;D:In

spring hibernate-org.springframework.beans.factory.BeanCreationException

问题描述 org.springframework.beans.factory.BeanCreationException applicationContext.xml文件 <?xml version=""1.0"" encoding=""UTF-8""?> xmlns=""http://www.springframework.org/schema/beans"" xmlns:

求解决org.springframework.beans.factory.BeanCreationException

问题描述 dwr和spring整合时出的问题,请问有谁知道这是怎么回事呢? 具体代码如下: dwr.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">

跪求大神帮解决org.springframework.beans.factory.BeanCreationException: Error creating b

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0':Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.Be

javase-关于Myeclipse的错误org.springframework.beans.factory.BeanCreationException

问题描述 关于Myeclipse的错误org.springframework.beans.factory.BeanCreationException 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreati

求解:org.springframework.beans.factory.BeanCreationException

问题描述 配置文件<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframew

springmvc-org.springframework.beans.factory.BeanCreationException:

问题描述 org.springframework.beans.factory.BeanCreationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [application.xml]: Error setting property values; nested

org.springframework.beans.factory.BeanCreationException: Error creating bean wit

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'txEasyjwebProcessorAdvice':Cannotresolvereferencetobean'transactionManager'whilesettingbeanproperty'transactionManager';nestedexceptionisorg.springframework.beans.