『 spring2.5和Ibatis2整合』
spring配置文件如下:<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="jdbc:sqlserver://localhost:1433;databaseName=Employ"> </property>
<property name="url" value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="username" value="sa"> </property>
<property name="password" value="123"> </property>
</bean> <!--根据dataSource和configLocation创建一个SqlMapClient-->
    <!-- org.springframework.orm.ibatis.SqlMapClientFactoryBean -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="configfile/sql-map-config.xml" />
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--根据sqlMapClien创建一个SqlMapClient模版类--> <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<!--将上面的模版类织入到我们的DAO对象中-->
<bean id="employDao" class="dao.MpsTestDaoImpl">
<property name="sqlMapClientTemplate">
<ref bean="sqlMapClientTemplate" />
</property>
</bean></beans>在applicationContext.xml文件中不知道怎么配,我初次自学ibatis望大虾赐教     错误详细信息如下: Error creating bean with name 'sqlMapClient' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at test.Test.main(Test.java:19)
Caused by: java.lang.NoSuchMethodError: com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:339)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertiesSet(SqlMapClientFactoryBean.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 15 more

解决方案 »

  1.   

    把sqlMapClientTemplate删了
    DAO直接注入sqlMapClient就行了
    <bean id="employDao" class="dao.MpsTestDaoImpl">
    <property name="sqlMapClientTemplate">
    <ref bean="sqlMapClient" />
    </property>
    </bean>
      

  2.   

    改了还是一样的错
    <!--根据dataSource和configLocation创建一个SqlMapClient-->
      <!-- org.springframework.orm.ibatis.SqlMapClientFactoryBean -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="configfile/sql-map-config.xml" />
    <property name="dataSource" ref="dataSource"></property>
    </bean>报的就是这段的异常,反正是读取并解析spring这个配置文件有问题,我硬是没试出来,不知道错在哪个细节上  呵呵~~
      

  3.   

    看你的写法,还要手写DAO,请参考一下:myBatis3 的使用-结合spring3(http://www.yulei.name/?p=413)。不需要手写DAO即可实现。如果要完整的配置文件样例,可以找我要。
      

  4.   

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

  5.   

    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at test.Test.main(Test.java:19)
    Caused by: java.lang.NoSuchMethodError: com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;
    at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:339)请确定红色标记处的文件
      

  6.   

    初始化sqlMapClient 时候出错。你看看,是否配置对了。
      

  7.   

    sql-map-config.xml 配置如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMapConfig        
        PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"        
        "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">  
    <sqlMapConfig>
    <sqlMap resource="cofigfile/MpsTest.xml" />
    </sqlMapConfig> 
    MpsTest.xml配置如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap      
        PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
        "http://ibatis.apache.org/dtd/sql-map-2.dtd">
    <sqlMap namespace="MpsTest">
    <typeAlias alias="mploy" type="test.Employ" /> <resultMap id="EmployResult" class="Employ">
    <result property="id" column="id" />
    <result property="enployName" column="enployName" />
    <result property="salary" column="salary" />
    </resultMap> <!--
    Select with no parameters using the result map for Account class.
    -->
    <select id="selectAllEmploy" resultMap="EmployResult">  
          <![CDATA[  
              select * from Employ  
          ]]>
    </select>
    <!--
    A simpler select example without the result map. Note the aliases to
    match the properties of the target result class.
    --> <!-- Insert example, using the Account parameter class -->
    <insert id="insertEmploy" parameterClass="Employ">  
          <![CDATA[  
              insert into Employ (enployName, salary) values(#enployName#, #salary#)  
          ]]>
    </insert> <!-- Update example, using the Account parameter class -->
    <update id="updateEmploy" parameterClass="Employ">
      <![CDATA[ 
             update Employ set enployName=#enployName#,salary=#salary# where id=#id#
      ]]>
    </update>
    <!-- Delete example, using an integer as the parameter class -->
    <delete id="deleteEmploy" parameterClass="java.lang.Integer">
      <![CDATA[
           delete from Employ where id=#id#
      ]]>
    </delete>
    </sqlMap> 
     
      

  8.   


    我也知道   但我是初次自学ibatis吗   关键是错在哪呢
      

  9.   

    property name="configLocation" value="configfile/sql-map-config.xml" /> 
    说明   configfile下有sql-map-config.xml
    但你的sql-map-config.xml里面
    <sqlMapConfig>
    <sqlMap resource="cofigfile/MpsTest.xml" />
    </sqlMapConfig> 
    那么你的MpsTest.xml在configfile/configfile下??
      

  10.   

    把那俩配置文件都按照格式发出来好吧?连web.xml也一起。
      

  11.   

    /**
     * Build a SqlMapClient instance based on the given standard configuration.
     * <p>The default implementation uses the standard iBATIS {@link SqlMapClientBuilder}
     * API to build a SqlMapClient instance based on an InputStream (if possible,
     * on iBATIS 2.3 and higher) or on a Reader (on iBATIS up to version 2.2).
     * @param configLocations the config files to load from
     * @param properties the SqlMapClient properties (if any)
     * @return the SqlMapClient instance (never <code>null</code>)
     * @throws IOException if loading the config file failed
     * @see com.ibatis.sqlmap.client.SqlMapClientBuilder#buildSqlMapClient
     */