| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1108 人关注过本帖
标题:spring集成ibatis问题
只看楼主 加入收藏
magiclaugh3
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-8-20
收藏
 问题点数:0 回复次数:0 
spring集成ibatis问题
applicationContext.xml
<!-- 配置事务特性 -->

    <tx:advice id="txAdvice" transaction-manager="txManager">

        <tx:attributes>

          <tx:method name="add*" propagation="REQUIRED"/>

          <tx:method name="del*" propagation="REQUIRED"/>

          <tx:method name="update*" propagation="REQUIRED"/>

          <tx:method name="*" read-only="true"/>

      </tx:attributes>

    </tx:advice>

   

    <!-- 配置哪些类的方法需要进行事务管理 -->

    <aop:config>

      <aop:pointcut id="allManagerMethod" expression="execution(* add*(..))"/>

      <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>

    </aop:config>


    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

    <property name="dataSource" ref="dataSource"/>

    </bean>

    <bean id="dataSource" class="org.

        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>

        <property name="url" value="jdbc:sqlserver://localhost:1433;databasename=test"/>

        <property name="username" value="sa"/>

        <property name="password" value=""/>

    </bean>

<bean id="userDAO" class="dao.imp.BeanDaoImp">

    <property name="sqlMapClient" ref="sqlMapClient"/>
      
</bean>


<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

    <property name="configLocation"> <value>classpath:SqlMapConfig.xml </value> </property>

    <property name="dataSource" ref="dataSource"> </property>

</bean>


SqlMapConfig.xml
<sqlMapConfig>

    <settings

      lazyLoadingEnabled="true"

        useStatementNamespaces="true" />
  

  <sqlMap resource="com/tx/vo/Users.xml"/>

</sqlMapConfig>


Users.xml
<sqlMap namespace="Users">

    <typeAlias alias="users" type="com.tx.vo.Users"/>

    <cacheModel id="usersCache" type="MEMORY" readOnly="false" serialize="true">
        <flushInterval hours="24"/>
        <flushOnExecute statement="Users.update"/>
        <flushOnExecute statement="Users.insert"/>
        <flushOnExecute statement="Users.delete"/>
    </cacheModel>

    <resultMap id="usersResult" class="users">
    <result property="id" column="id"/>
        <result property="username" column="username"/>
        <result property="age" column="age"/>
    </resultMap>

    <!-- hsql db used for this example capitalizes col names
        so Map will have them as all caps -->
    <select id="getAll" resultClass="users"> <!--  cacheModel="usersCache" 这个加了报错 -->
        SELECT
        id,
            username,        
            age      
        FROM users
    </select>

    <select id="getById" resultMap="usersResult" parameterClass="java.lang.Integer">
        SELECT id,username, age
        FROM users
        WHERE id = #value#            
    </select>

    <update id="update" parameterClass="users">
        UPDATE users
        SET
            username = #username#,         
            age = #age#         
        WHERE id = #id#
    </update>

    <insert id="insert" parameterClass="users" >
        INSERT INTO users (username, age)
        VALUES (#username#, #age#)
    </insert>

    <delete id="delete" parameterClass="java.lang.Integer">
        DELETE FROM users WHERE id = #value#
    </delete>
</sqlMap>


dao.imp.BeanDaoImp.java
public class BeanDaoImp extends SqlMapClientDaoSupport implements BeanDao {

    public void addBean(Users u) {
this.getSqlMapClientTemplate().insert("Users.insert", u);
    }
}


测试类
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        BeanDao dao = (BeanDao) ctx.getBean("userDAO");
        Users u = new Users();
        u.setId(22);
        u.setUsername("tx");
        dao.addBean(u);


我现在程序执行到
this.getSqlMapClientTemplate()都没事,一调this.getSqlMapClientTemplate().insert("Users.insert", u);
就出错
java.lang.NoSuchMethodError: com.ibatis.sqlmap.client.SqlMapSession.getCurrentConnection()Ljava/sql/Connection;
搜索更多相关主题的帖子: ibatis spring 
2008-08-27 19:47
快速回复:spring集成ibatis问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025867 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved