本实例在ssh框架基础上实现 oracle和mysql 2个数据库连接
一:db-config.properties:(数据源配置)
hibernate.cglib.use_reflection_optimizer=true
hibernate.connection.proxool_provider_class=org.hibernate.connection.ProxoolConnectionProvider
hibernate.connection.c3p0_provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.proxool.pool_alias=spring
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.hbm2ddl.auto=update
hibernate.default_schema=mySchema
#mysql数据库
mysql.hibernate.dialect=org.hibernate.dialect.MySQLDialect
mysql.datasource.driverClassName=com.mysql.jdbc.Driver
mysql.datasource.url=jdbc:mysql://localhost:3306/youth?useUnicode=true&characterEncoding=utf8
mysql.datasource.username=root
mysql.datasource.password=root
#oracle数据库
oracle.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
#oracle.hibernate.dialect=com.common.jdbc.OracleDialectExtType
oracle.hibernate.dialect=org.hibernate.dialect.OracleDialect
oracle.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:ORCL
oracle.datasource.username=scott
oracle.datasource.password=scott
datasource.testSql=select current_date from dual
二:spring.xml配置:
注意:配置spring.xml时
1.可以多个数据源,名字随意
2.可以多个sessionFactory,名字随意
3.可以多个hibernateTemplate,名字随意(但至少有一个名字为 hibernateTemplate,本人亲测,可能是刚好碰上了, 如果有人测试不是这样,请勿喷)
4.可以多个transactionManager,名字随意
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/jee
http://www.springframework.org/schema/jee/spring-jee-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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tool
http://www.springframework.org/schema/tool/spring-tool.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"
default-autowire="byName" default-lazy-init="true">
<context:annotation-config />
<!-- 自动扫描 -->
<context:component-scan base-package="com,com.baseSystem.web.*" />
<!-- 强制使用CGLIB代理 -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!--连接池配置-->
<context:property-placeholder location="classpath:jdbc/db-config.properties" />
<!-- oracle数据库 -->