<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:configure.properties</value>
<value>classpath:resources.properties</value>
</list>
</property>
</bean>
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor"/>
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>
<bean id="sessionFactory" class="org.rd.framework.hibernate.ConfigurableSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.query.substitutions">true=1,false=0</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.region_prefix">direct</prop>
<prop key="hibernate.cache.use_structured_entries">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
</props>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources" ref="mappingResources"/>
<property name="lobHandler" ref="oracleLobHandler"/>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>
<property name="maxStatements" value="${c3p0.maxStatements}"/>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/>
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sessionFactoryItsm" class="org.rd.framework.hibernate.ConfigurableSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.query.substitutions">true=1,false=0</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.region_prefix">direct</prop>
<prop key="hibernate.cache.use_structured_entries">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
</props>
</property>
<property name="dataSource" ref="dataSourceItsm"/>
<property name="mappingResources" ref="mappingResources"/>
<property name="lobHandler" ref="oracleLobHandler"/>
</bean>
<bean id="dataSourceItsm" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>
<property name="maxStatements" value="${c3p0.maxStatements}"/>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/>
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${itsm.jdbc.url}"/>
<property name="user" value="${itsm.jdbc.username}"/>
<property name="password" value="${itsm.jdbc.password}"/>
</bean>
<bean id="transactionManagerItsm" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryItsm"/>
</bean>
<bean id="transactionProxyTemplateItsm" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManagerItsm"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="query*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionProxyTemplate" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="query*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplateItsm" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSourceItsm"/>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
</beans>
使用不同数据源在接口中配置即可
使用数据源dataSource
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="HDLoginService" parent="transactionProxyTemplate">
<property name="target">
<bean class="org.hd.login.service.impl.LoginServiceImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</property>
<property name="proxyInterfaces">
<value>org.hd.login.service.LoginService</value>
</property>
</bean>
</beans>
使用数据源dataSourceItsm
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="businessServiceItsm" parent="transactionProxyTemplate">
<property name="target">
<bean class="org.hd.business.service.impl.BusinessServiceImplItsm">
<property name="sessionFactory">
<ref bean="sessionFactoryItsm"/>
</property>
</bean>
</property>
<property name="proxyInterfaces">
<value>org.hd.business.service.BusinessServiceItsm</value>
</property>
</bean>
<bean id="businessService" parent="transactionProxyTemplate">
<property name="target">
<bean class="org.hd.business.service.impl.BusinessServiceImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</property>
<property name="proxyInterfaces">
<value>org.hd.business.service.BusinessService</value>
</property>
</bean>
</beans>
分享到:
相关推荐
本示例主要介绍如何实现Spring Boot 2.0多数据源的集成,并结合Hibernate进行配置,特别是在DAO层使用`HibernateDaoSupport`进行操作,而非使用JPA(Java Persistence API)。 首先,让我们了解Spring Boot 2.0的...
在SpringBoot框架中,我们通常会使用`@ConfigurationProperties`注解来配置数据源,并通过`@Primary`注解指定默认数据源。 1. **配置数据源** - 创建两个数据源配置类,分别代表不同的数据库。例如,`...
3. **配置数据源路由**:为了在代码中动态选择使用哪个数据源,可以使用`AbstractRoutingDataSource`,它可以根据预设的规则或运行时条件决定使用哪个数据源。 4. **配置Hibernate和MyBatis**:为每个数据源配置...
Hibernate 多数据库配置 在 Hibernate 中配置多数据库,并自由切换,可以使用 Spring 框架来实现。...使用 Spring 框架和 Hibernate,我们可以轻松地配置多数据库连接信息,并自由切换不同的数据源。
Hibernate配置各种数据源 <hibernate-configuration> <!– 各属性的配置–> <!—为true表示将Hibernate发送给数据库的sql显示出来 –> ”show_sql”>true <!– SQL方言,这边设定的是MySQL –> ”dialect”>...
### Hibernate配置数据源详解 #### 一、引言 在软件开发过程中,特别是涉及大量数据库交互的应用场景下,选择合适的数据源配置对于提高系统性能、稳定性具有重要意义。Hibernate作为Java领域内广泛使用的对象关系...
在多数据源场景下,Hibernate可以配置为连接不同的数据库,使得应用可以根据业务需求灵活切换数据源。 **多数据源** 是指在一个应用中管理多个独立的数据库连接。在本项目中,数据源被配置为Hibernate和Datastore,...
在Spring+Hibernate的整合模式下,通常会在Spring的applicationContext.xml中配置数据源,并通过Spring的IoC容器将数据源注入到SessionFactory中。这样,SessionFactory就可以利用该数据源进行数据库的CRUD操作。 ...
3. 创建Hibernate配置文件。通常该文件命名为hibernate.cfg.xml,并放置在项目的src目录下。配置文件中需要声明以下关键内容: - 数据库方言(Dialect):指定Hibernate针对哪种数据库优化其SQL语句。 - 连接...
我们可以为每个数据源创建一个SessionFactory配置,并指定相应的DataSource,实体扫描路径,以及其他的Hibernate配置参数。 在"压缩包子文件的文件名称列表"中,只有一个名为"RouterAssistant"的文件。这可能是实现...
"Spring3+Hibernate4+Maven+JUnit 多库多数据源实现"是一个典型的Java Web项目配置,它涉及了多个核心技术来处理复杂的数据管理需求。下面将详细阐述这些技术以及如何协同工作以实现多库多数据源。 首先,Spring...
一个hibernate数据源的c3p0配置,希望对你有帮助
除了通过Properties文件配置数据源外,还可以选择使用JNDI(Java Naming and Directory Interface)来管理数据源。这种方式常用于Web容器(如Tomcat、JBoss等)中,可以实现更高级别的连接池管理和配置。以下是在...
2. 配置数据源:为每个数据源创建一个DataSource实例,这可以通过Spring的Bean定义来完成,也可以通过Atomikos的UserTransactionService来创建和管理。 3. 配置Hibernate:在Hibernate的配置文件(hibernate.cfg....
接下来,我们需要在Hibernate配置中引用这些数据源。在hibernate.cfg.xml中,可以这样设置: ```xml <property name="hibernate.connection.datasource">dataSource1 <!-- 其他Hibernate配置 --> ...
8. **配置数据源**:配置数据源涉及到服务器、数据库驱动、连接池相关的jar包以及具体的XML配置文件。 【部分内容】中的知识点: 9. **数据源的作用**:数据源降低了应用程序与数据库之间的耦合度,通过连接池管理...
1. **配置数据源**:在Spring的配置文件中定义多个DataSource bean,每个bean代表一个数据源。例如,我们可以分别为生产环境和测试环境设置不同的数据源。 2. **配置SessionFactory**:为每个数据源创建一个...
在配置 Hibernate 数据源时,通常会通过 XML 配置文件(如 `hibernate.cfg.xml`)或 Java 配置类(在 Spring Boot 中常见)来指定。例如,在 XML 文件中,可以这样配置 BasicDataSource: ```xml <!-- ...
该配置文件连接的是两个数据库结构相同的数据源,其他比如数据库结构不原理也可行。本人在遇到此问题时上网搜了很多答案结果都不怎么如意,有的太深奥不过思想很好,有的又太不给力,后来自己慢慢研究配置成功后想与...
- **`hibernateProperties`**: Hibernate配置属性。 - **dialect**: 数据库方言,用于生成SQL语句。 - **hibernate.hbm2ddl.auto**: 控制Hibernate自动建表行为。 - **hibernate.show_sql**: 是否显示SQL语句。 -...