forked from SnDragon/JavaLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspring-mybatis.xml
More file actions
96 lines (82 loc) · 3.44 KB
/
spring-mybatis.xml
File metadata and controls
96 lines (82 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 引入我们的database.properties,hibernate.properties文件 -->
<bean id="property" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:database.properties</value><!-- classpath代表类路径,如src下面的文件 -->
</list>
</property>
</bean>
<!-- 定义使用C3P0连接池的数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!-- 指定连接数据库的JDBC驱动 -->
<property name="driverClass">
<value>${mysql.driver_class}</value>
</property>
<!-- 连接数据库所用的URL -->
<property name="jdbcUrl">
<value>${mysql.connection.url}</value>
</property>
<!-- 连接数据库的用户名 -->
<property name="user">
<value>${mysql.connection.username}</value>
</property>
<!-- 连接数据库的密码 -->
<property name="password">
<value>${mysql.connection.password}</value>
</property>
<!-- 设置数据库连接池的最大连接数 -->
<property name="maxPoolSize">
<value>30</value>
</property>
<!-- 设置数据库连接池的最小连接数 -->
<property name="minPoolSize">
<value>2</value>
</property>
<!-- 设置数据库连接池的初始化连接数 -->
<property name="initialPoolSize">
<value>2</value>
</property>
<!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 -->
<property name="maxIdleTime">
<value>10</value>
</property>
</bean>
<!-- 启用自动扫描 -->
<context:component-scan base-package="com.crm.*">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" /><!-- 排除注解为controller的类型 -->
</context:component-scan>
<!-- 配置SqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- mapper和resultmap配置路径 -->
<property name="mapperLocations">
<list>
<value>classpath:com/crm/mapping/*.xml</value>
</list>
</property>
</bean>
<!-- 自动扫描mapper接口,注入sqlsessionfactory -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.crm.dao"/>
</bean>
<!-- 开启 mybatis事务-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>