<!--集成所需的嫁包-->
<dependency>
<groupId>org.mybatis</groupId>
<!--mybatis-spring:有mybatis提供的集成-->
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!--dbcp连接池-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.3</version>
</dependency>
项目所有嫁包(可直接V进去)
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<!--日志 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<!--集成所需的嫁包-->
<dependency>
<groupId>org.mybatis</groupId>
<!--mybatis-spring:有mybatis提供的集成-->
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!--dbcp连接池-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!--1. 注解式开发 -->
<!--1) 注解驱动,用于激活已经在spring容器中注册过的bean上面的注解-->
<!--<context:annotation-config/>-->
<!-- 2) 用注解方式注入bean,并指定查找范围:com.zking.oa及子子孙孙包,使用了该注解后,context:annotation-config注解可以省略 -->
<!--组件扫描器-->
<context:component-scan base-package="com.zking"/>
<!--2. 引入外置jdbc配置文件 -->
<!-- 第一种方式
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
-->
<!--数据库的连接-->
<!-- 第二种方式,比第一种方式更简洁,第一种方式更好理解一些 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--3. dbcp2数据库连接池配置-->
<!--dbcp2数据库连接池-->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!--初始连接数-->
<property name="initialSize" value="10"/>
<!--最大活动连接数-->
<property name="maxTotal" value="100"/>
<!--最大空闲连接数-->
<property name="maxIdle" value="50"/>
<!--最小空闲连接数-->
<property name="minIdle" value="10"/>
<!--设置为-1时,如果没有可用连接,连接池会一直无限期等待,直到获取到连接为止。-->
<!--如果设置为N(毫秒),则连接池会等待N毫秒,等待不到,则抛出异常-->
<property name="maxWaitMillis" value="-1"/>
<!--MySQL连接8小时问题:超过8小时后数据库单方面关闭连接-->
<!--测试空闲连接:发一个sql语句value="select 1"测试连接-->
<property name="testWhileIdle" value="true"></property>
<property name="validationQuery" value="select 1"></property>
</bean>
<!--4. spring和MyBatis整合 -->
<!--1) 创建sqlSessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 指定数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 指定mybatis核心配置文件 -->
<!-- <property name="configLocation" value="classpath:mybatis.cfg.xml"/>-->
<!-- 自动扫描XxxMapping.xml文件,**表示迭代查找 -->
<property name="mapperLocations" value="classpath:/mapper/**/*.xml"/>
<!--插件-->
<property name="plugins">
<list>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<!-- config params as the following -->
<value>
<!--分页插件需要考虑MySQL数据库-->
helperDialect=mysql
</value>
</property>
</bean>
</list>
</property>
</bean>
<!--2) 自动扫描com/zking/oa/**/mapper下的所有XxxMapper接口(其实就是DAO接口),并实现这些接口-->
<!-- 即可直接在程序中使用dao接口,不用再获取sqlsession对象-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--basePackage 属性是映射器接口文件的包路径。-->
<!--你可以使用分号或逗号 作为分隔符设置多于一个的包路径-->
<property name="basePackage" value="com/zking/**/mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!--5. 声明式事务配置开始 -->
<!--1) 开启自动代理 -->
<aop:aspectj-autoproxy/>
<!--2) 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 注解式事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/a_text?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
jdbc.username=root
jdbc.password=54123434545456