- Spring+JDBC组合开发配置数据源有两种方式:
- 1.基于XML
- 2.基于注解
- 首先我们看看基于XML的配置:
- 步骤:
- 1.首先导入我们数据源依赖的jar包,如下图
- 2.写beans.xml配置文件,配置事务时,需要在xml配置文件中引入用于声明事务的tx命名空间
- 比以前的配置文件多了
- xmlns:tx="http://www.springframework.org/schema/tx"
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- Java代码
- <?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-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
来自 http://www.haowanw.com/bbs/viewthread.php?tid=196&extra=page%3D2