ibatis 配置
来源:互联网 发布:windows远程linux工具 编辑:程序博客网 时间:2024/05/06 10:45
1、引入相应的包:
2、jdbc.properties
1
jdbc.driver=com.mysql.jdbc.Driver
2
jdbc.url=jdbc:mysql://localhost:3306/test
3
jdbc.username=root
4
jdbc.password=admin
applicationContext.xml
01
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
02
<
beans
xmlns
=
"http://www.springframework.org/schema/beans"
03
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
04
xmlns:aop
=
"http://www.springframework.org/schema/aop"
05
xmlns:tx
=
"http://www.springframework.org/schema/tx"
06
xmlns:context
=
"http://www.springframework.org/schema/context"
07
xsi:schemaLocation="http://www.springframework.org/schema/beans
08
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
09
http://www.springframework.org/schema/aop
10
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
11
http://www.springframework.org/schema/tx
12
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
13
http://www.springframework.org/schema/context
14
http://www.springframework.org/schema/context/spring-context-2.5.xsd" >
15
16
<
context:annotation-config
/>
17
<!-- 根据base-package指定的路径,扫描其下所有包含注解的Bean,并自动注入 -->
18
<
context:component-scan
base-package
=
"com.huawei.boss"
/>
19
20
<!-- 启用aspectj -->
21
<!-- <aop:aspectj-autoproxy /> -->
22
23
<!-- 自动加载 jdbc.properties -->
24
<
bean
id
=
"globalConfig"
25
class
=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
>
26
<
property
name
=
"locations"
>
27
<
list
>
28
<
value
>classpath:jdbc.properties</
value
>
29
</
list
>
30
</
property
>
31
</
bean
>
32
33
<
bean
id
=
"dataSource"
class
=
"org.apache.commons.dbcp.BasicDataSource"
>
34
<
property
name
=
"driverClassName"
value
=
"${jdbc.driver}"
/>
35
<
property
name
=
"url"
value
=
"${jdbc.url}"
/>
36
<
property
name
=
"username"
value
=
"${jdbc.username}"
/>
37
<
property
name
=
"password"
value
=
"${jdbc.password}"
/>
38
</
bean
>
39
40
<!-- 配置hibernate
41
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
42
<property name="dataSource" ref="dataSource"/>
43
<property name="hibernateProperties">
44
<props>
45
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
46
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
47
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
48
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
49
</props>
50
</property>
51
-->
52
<!-- 根据value中定义的路径来扫描其下所有的注解实体类 -->
53
54
<!--
55
<property name="packagesToScan" value="com.huawei.boss.entity.*"></property>
56
</bean>
57
-->
58
59
<!-- 读取ibatis配置文件 -->
60
<
bean
id
=
"sqlMapClient"
class
=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean"
>
61
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
62
<
property
name
=
"configLocation"
>
63
<
value
>classpath:SqlMapConfig.xml</
value
>
64
</
property
>
65
</
bean
>
66
67
<!-- 使用Spring的Template 进行数据库管理 -->
68
69
<
bean
id
=
"sqlMapClientTemplate"
class
=
"org.springframework.orm.ibatis.SqlMapClientTemplate"
>
70
<
property
name
=
"sqlMapClient"
ref
=
"sqlMapClient"
/>
71
</
bean
>
72
73
<!-- 提供对SqlMapClientTemplate的封装 -->
74
<!--
75
<bean id="sqlMapClientTemplateManager" class="com.huawei.boss.common.dao.SqlMapClientTemplateManagerImpl">
76
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate" />
77
</bean>
78
-->
79
80
81
<!-- 配置事务定义 ibatis -->
82
<
bean
id
=
"transactionManager"
class
=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
83
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
84
</
bean
>
85
86
<!-- 注解方式定义事务(@Transactional),proxy-target-class="true"表示采用动态代理类来管理事务,如果是false表示采用接口代理来管理事务(默认值为false) -->
87
<
tx:annotation-driven
transaction-manager
=
"transactionManager"
proxy-target-class
=
"true"
/>
88
89
<!-- 采用jta事务管理
90
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
91
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
92
<property name="userTransaction">
93
<ref local="jotm"/>
94
</property>
95
</bean>
96
<tx:annotation-driven transaction-manager="jtaTransactionManager" proxy-target-class="true" />
97
-->
98
</
beans
>
- ibatis 配置
- ibatis配置
- SpringMVC+IBatis之IBatis配置
- spring+ibatis事务处理配置
- ibatis 配置cdata
- spring+ibatis事务处理配置
- ibatis 配置问题
- 为ibatis配置缓存
- IBatis 配置详解
- ibatis 的简单配置
- ibatis实例配置
- ibatis配置详解
- ibatis配置详解二
- ibatis配置问题
- ibatis SqlMapConfig.xml 配置
- iBatis基本配置解释
- IBatis 配置详解
- ibatis配置(1)
- loadbalance&cluster
- 转:诡异的VB多线程和回调函数(给VB程序做进度条真是烦人啊)
- PHP截取字符串后四位
- 点到平面的垂足
- 平面方程
- ibatis 配置
- 几个关于单链表的小操作
- void类型及void指针类型
- 物联网会是下一个互联网吗?
- STL基础
- 关于java代码中的注释问题。(类中方法的注释,我们一般都要写上这个方法的文档(doc),方法的参数也要有它的文档)
- SecureCRT ssh连接自动断开问题
- 一年工作生活总结(转)
- Word中动态的L连续插入多个表格