专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
java
当前位置:首页 > 技术文档 > java >  > 
Ibatis整合SpringStruts2

<?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-3.0.xsd">
 <!-- 引入参数配置文件 -->
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <list>
    <value>classpath:jdbc.properties</value>
   </list>
  </property>
 </bean>
 <!-- 配置数据源  -->
 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="driverClass"><value>${jdbc.driverClass}</value></property>
  <property name="jdbcUrl"><value>${jdbc.url}</value></property>
  <property name="user"><value>${jdbc.user}</value></property>
  <property name="password"><value>${jdbc.password}</value></property>
  <property name="initialPoolSize"><value>${jdbc.initialPoolSize}</value></property>
  <property name="minPoolSize"><value>${jdbc.minPoolSize}</value></property>
  <property name="maxPoolSize"><value>${jdbc.maxPoolSize}</value></property>
 </bean>
 <!-- ibatis sqlMapClient 配置 -->
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation">
            <value>classpath:sqlMapConfig.xml</value>
        </property>
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>   
 </bean>
<!-- dao配置  -->
<bean id="userdao" class="com.qingruxu.dao.impl.UserDaoImpl">
<property name="sqlMapClient"><ref bean="sqlMapClient"></ref></property>
</bean>
<!-- action 配置 -->
<bean id="user" class="com.qingruxu.action.UserAction">
<property name="userdao"><ref bean="userdao"></ref></property>
</bean>
</beans>

<?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>
    <settings lazyLoadingEnabled="true" useStatementNamespaces="true" />
    <!-- 使用spring之后,数据源的配置移植到了spring上,所以iBATIS本身的配置可以取消 -->
    <sqlMap resource="User.xml" />
</sqlMapConfig>