读书人

容易的spring和mybatis整合的配置文件

发布时间: 2013-08-01 15:23:18 作者: rapoo

简单的spring和mybatis整合的配置文件

<?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"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"default-autowire="byName"><context:component-scan base-package="com" /><bean id="dataSource" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://localhost:3306/db" /><property name="username" value="" /><property name="password" value="" /></bean><bean id="sqlSessionFactory" ref="dataSource" /><property name="mapperLocations"value="classpath:com/?/mapper/*Mapper.xml" /><!-- 指定别名的类的包<property name="typeAliasesPackage" value="com" /> --></bean><!-- 这种方式需要每个dao都写一个bean     <bean id="testDao"             value="com.?.dao.TestDao" />         <property name="sqlSessionFactory" ref="sqlSessionFactory" />      </bean> --><!-- 重要就是这个类,来自mytatis spring,它可以自动扫描所有dao类,为他们提供mybatis实现和依赖注入-->       <bean value="com.?.dao" />  </bean> </beans>

?

读书人网 >开源软件

热点推荐