<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- 创建数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</bean>
<!-- mybatis配置,sqlsession -->
<bean id="dataSource" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 配置mybatis的数据类型 -->
<property name="typeAliases" value="com.zll.entity"></property>
<!-- 配置加载mybatis的xml文件 -->
<property name="mapperLocations" value="classpath:com/zll/dao/*.xml"></property>
</bean>
<!-- 配置mybatis数据输入映射资源 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.zll.dao"></property>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 开启事务的注解 -->
<tx:annotation-driven/>
</beans>
spring.xml
最新推荐文章于 2023-12-01 11:11:20 发布
本文介绍了如何使用Spring Boot与MyBatis结合,配置数据源、SqlSessionFactory,并利用MapperScannerConfigurer扫描DAO接口,实现持久层的轻量级集成。
445

被折叠的 条评论
为什么被折叠?



