spring与jdbc整合
2016-09-27 21:44
357 查看
spring+jdbc开发,我使用的是c3p0连接池
1、数据库建表:
beans.xml
1、数据库建表:
<?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/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.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <context:component-scan base-package="cn.itcast"/> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClassName}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="maxPoolSize" value="${jdbc.maxPoolSize}"/> <property name="minPoolSize" value="${jdbc.minPoolSize}"/> <property name="initialPoolSize" value="${jdbc.initialPoolSize}"/> <property name="maxIdleTime" value="${jdbc.maxIdleTime}"/> <property name="acquireIncrement" value="${jdbc.acquireIncrement}"/> </bean> <!-- 装载spring提供的针对数据源的事务管理器 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 打开注解配置管理事务的处理器 --> <tx:annotation-driven transaction-manager="txManager"/> <aop:config> <aop:pointcut expression="execution(* cn.itcast.service..*.*(..))" id="mycut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/> <tx:method name="*"/> </tx:attributes> </tx:advice> </beans>
beans.xml
相关文章推荐
- Struts2 入门(三) 之 配置文件的常量设置
- 今天给大家介绍一下SpringBoot框架中URL参数如何进行Base64加密解密
- MyEclipse 10 for mac配置JDK1.6
- (笔记)Spring实战_征服数据库(3)_在Spring中使用JDBC
- Spring-使用注解方式装配对象
- java中定义“全局变量”的方法【菜鸟学java】
- Struts2 入门(二) 之 配置文件中的 Action 元素
- Spring学习笔记(二)后处理器与AOP
- Struts2 入门(一) 之 控制器与执行步骤
- Java之 byte[]转String问题
- 用户登录相关问题
- Java web video 视频开发
- Java之 无符号类型是怎么回事
- java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符 分号问题
- 搭建Dubbo+Myeclipse2015+Maven3.3.1的过程遇到问题集锦
- 02.Spring Ioc 容器 - 创建
- Struts2与OGNL表达式
- 使用Spring注解注入属性
- SpringAOP使用入门,如何对自定义的注解进行切面编程
- Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符