JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
2013-11-01 15:00
736 查看
JdbcTemplate的使用
Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调。
JdbcTemplate 简化 JDBC 操作
HibernateTemplate 简化 Hibernate 操作
下面列出几种熟悉的
View Code
Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调。
JdbcTemplate 简化 JDBC 操作
HibernateTemplate 简化 Hibernate 操作
下面列出几种熟悉的
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 配置数据库连接池 --> <!-- 引入外部 properties 文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置c3p0 连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}"></property> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="user" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <!-- 将连接池注入 jdbcTemplate --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置DAO --> <bean id="personDAO" class="cn.itcast.dao.PersonDAO"> <property name="jdbcTemplate" ref="jdbcTemplate"></property> </bean> </beans>
View Code
相关文章推荐
- spring 配置文件中dbcp连接池,jdbc连接池 引入 配置文件properties,但是不能用$符号引用里面的变量问题
- spring配置文件中引用外部的properties文件
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- Spring4深入理解IOC&DI02----Bean配置--自动装配、bean之间的继承与依赖、使用外部属性文件
- 让spring的配置文件可以使用外部properties里的参数。
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- spring boot 使用application.properties 进行外部配置
- Spring 使用Properties配置文件(一)
- Spring 使用Properties配置文件(二)
- Spring初学之使用外部配置文件dataSource
- SpringBoot 使用properties配置文件实现多环境配置
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- Spring/Maven/MyBatis配置文件结合properties文件使用
- spring boot application.properties文件外部配置
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- Spring中使用proxool连接池的配置方式与出现Attempt to refer to a unregistered pool by its alias 'ums'异常的解决办法
- springboot 使用外部配置文件
- Spring/Maven/MyBatis配置文件结合properties文件使用
- Mybatis在非spring环境下配置文件中使用外部数据源(druidDatasource)
- 22Spring_JdbcTemplatem模板工具类的使用——使用外部属性文件来配置(properties)