2013-05-07期-加入Spring3.2\MyBatis3.2框架

这次加入了最新的Spring框架和MyBatis框架

下面是所需要的Jar包,代码已上传,请返回总目录内容下载

 

贴出部分xml配置文件代码

applicationContext.xml

    <!-- 自动扫描并注入 --> 
    <context:component-scan base-package="com.searchengine" />

    <!-- 配置DataSource数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/test" />
        <property name="username" value="root" />
        <property name="password" value="root" />
        <property name="initialSize" value="10" />
        <property name="maxActive" value="20" />
    </bean>

   <!-- 创建SqlSessionFactory,同时指定数据源 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
         <property name="mapperLocations" value="classpath*:com/earchengine/dao/*Mapper.xml" /> 
         <property name="configLocation" value="classpath:mybatis-config.xml"></property>  
    </bean>


    <bean id="articleDao" class="org.mybatis.spring.mapper.MapperFactoryBean">  
        <property name="mapperInterface" value="com.searchengine.dao.ArticleDao" />  
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
    </bean>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
"http://mybatis.org/dtd/mybatis-3-config.dtd">  
<configuration>  
    <typeAliases>
        <typeAlias alias="contentObject" type="com.searchengine.entity.ContentObject" />
    </typeAliases>
    <mappers>  
        <mapper resource="com/searchengine/dao/ArticleMapper.xml" />  
    </mappers>  
</configuration>

 

你可能感兴趣的:(Mybatis3)