俗话说:好记性不如烂笔头。况且,我记性还不好。于是,我开始记博文了!
不敢说给遇到类似问题的人以什么借鉴,但求我再遇到类似的问题时候,有处可查。
Spring+Hibernate多数据源的配置问题:
-----------------app-dataSourse.xml:-----------------------------------------------------------------------
<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
//数据源1
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@192.0.0.100:1555:orcl" />
<property name="user" value="xxx" />
<property name="password" value="xxx" />
<property name="initialPoolSize" value="5" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="idleConnectionTestPeriod" value="600" />
<property name="maxIdleTime" value="600" />
<property name="maxStatements" value="0" />
<property name="maxStatementsPerConnection" value="0" />
<property name="acquireIncrement" value="5" />
<property name="acquireRetryAttempts" value="200" />
<property name="acquireRetryDelay" value="180000" />
</bean>
<!--连接LNSJ数据库,读取“健康知识” -->
//数据源2
<bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@119.0.0.0:1555:orcl" />
<property name="user" value="xxx" />
<property name="password" value="xxx" />
<property name="initialPoolSize" value="5" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="idleConnectionTestPeriod" value="600" />
<property name="maxIdleTime" value="600" />
<property name="maxStatements" value="0" />
<property name="maxStatementsPerConnection" value="0" />
<property name="acquireIncrement" value="5" />
<property name="acquireRetryAttempts" value="200" />
<property name="acquireRetryDelay" value="180000" />
</bean>
</beans>
-----------------app-hibernate.xml:-----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 配置sessionFactory1 -->
<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
id="sessionFactory">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>hbm/TabMsColumn.hbm.xml</value>
<value>hbm/TabMsAd.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.jdbc.fetch_size">100</prop>
<prop key="hibernate.max_fetch_depth">2</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
</bean>
<!--LNSJ库“健康知识” SessionFactory -->
<!-- 配置sessionFactory1 -->
<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
id="sessionFactory2">
<property name="dataSource">
<ref bean="dataSource2" />
</property>
<property name="mappingResources">
<list>
<value>hbm/TabMsKnowledge.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.jdbc.fetch_size">100</prop>
<prop key="hibernate.max_fetch_depth">2</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionBase"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<!-- 配置事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="transactionManager2"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory2" />
</bean>
<bean id="transactionBase2"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<!-- 配置事务管理器 -->
<property name="transactionManager" ref="transactionManager2" />
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
-----------------app-dao.xml:-----------------------------------------------------------------------
<beans .......>
.......
<bean id="imeiDao" class="com.zmks.dao.impl.ImeiDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="knowledgeDao" class="com.zmks.dao.impl.IKnowledgeDaoImpl">
<property name="sessionFactory" ref="sessionFactory2" />
</bean>
........
<beans />
-----------------app-dao.xml:-----------------------------------------------------------------------
<beans .......>
.......
<bean id="knowledgeService" class="com.zmks.service.impl.KnowledgeServiceImpl">
<constructor-arg index="0" ref="knowledgeDao" />
</bean>
........
<beans />
我的J2EE还是很弱,多学习多学习!
分享到:
相关推荐
实现了spring3+springmvc+jpa2.0之间的集成,采用多数据源实现jpa,本例子提供的数据源为hibernate何datastore,为需要的朋友省去搭建框架的时间
Spring+Hibernate多数据源的整合实现demo
spring+hibernate解决多数据源问题3.pdf
Spring boot+Atomikos+JTA+Hibernate+MySQL实现分布式事务+多数据源,分别向两个不同的数据里面插入数据同时失败和成功,调用接口方式原理一样。
spring 3.2+ hibernate 3.* +atomikos3.9 配置多数据源 包含所有jar包和源代码,完整项目
strut+spring+hibernate注册登录系统,包括管理员登录,管理员对普通用户的增删改查;用户的注册,登录!对初学SSH框架的有很大的帮助!
在spring+hibernate的框架中定时操作数据库,主要是拿到sessionFactory,不会出现no session 和transaction no-bound等问题,由sessionFactory完成对数据的操作,有些包是没有用的,有兴趣的可以自己删除掉
spring+hibernate+atomikos实现多数据源分布式事务管理
5.单数据源配置(兼容Tomcat和Weblogic)。 6.Hibernate继承 HibernateDaoSupport。 7.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 2)Demo 导入说明: 1.Eclipse Encoding:GBK 2.Eclipse 导入后可能...
项目描述 辅助业务人员对工程财务状况...2.spring中关于DataSource的配置,需要在tomcat的conf/context.xml中添加数据源 3.PaymentServiceImpl.java中有个import错误 4.FMS.sql数据库文件较大,导入时间较长,请耐心
springboot2.0多数据源集成hibernate配置hibernateDaoSupport, dao层继承hibernateDaoSupport, 不使用jpa方式。
spring boot 2多数据源,里面有hibernate和mybatis的多数据源代码。代码拿过去即可集成使用。
(1)该项目是基于spring3+struts2+hibernate3+spring security3的权限管理项目 (2)后台我已经实现了权限管理,包括用户,角色和资源的分配。前台实现了spring security3的管理 (3)网上案例普遍是后台单一登陆。...
spring3+hibernate4+maven+junit 多库多数据源实现,非常好的一个学习多数据分点管理,分别连接不同类型数据源的方法
1.多数据源配置,采用方式:直接配置两个不同的数据源,不同的sessionFactory。 2.Spring+Jotm整合实现JTA分布式事务,应用场景如转账等,同一事务内完成db1用户加100元、db2用户减100元。 3.Spring+Junit4单元...
spring+jotm 多数据源事务管理(二)hibernate 使用hibernate关联jotm也很方便,先看一个没有使用jotm的例子:
项目中我们经常会遇到多数据源的问题,尤其是数据同步或定时任务等项目更是如此。多数据源让人最头痛的,不是配置多个数据源,而是如何能灵活动态的切换数据源。 此项目就是为了解决这个问题。
struts2+spring4+hibernate4整合时所用的所有jar包,包括c3p0数据源jar包
SSH整合学习笔记之struts2+spring+hibernate+c3p0源码
spring 3.29+struts2.3.15.1+hibernate3 动态切换数据源