【问题标题】:Hikari configuration in xml for Master/Slave Datasources用于主/从数据源的 xml 中的 Hikari 配置
【发布时间】:2016-09-20 09:18:36
【问题描述】:

目前,我在 applicationContext.xml 中使用 Hikari 配置了一个数据源。我想在同一个 xml 文件中为主/从类型的数据源进行配置。

另外我如何在同一个中建立一个新的实体管理器工厂?

为 1 个数据源(读取为主)配置的 applicationContext.xml 看起来像:

    <xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">

        <context:property-placeholder location="classpath*:META-INF/spring/*.properties" />

        <context:spring-configured />


        <context:component-scan base-package="com.lkart.dao">
        </context:component-scan>

    <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource"
            destroy-method="close">
            <property name="dataSourceClassName" value="${database.driverClassName}" />
            <property name="maximumPoolSize" value="10" />
            <property name="maxLifetime" value="1800000" />
            <property name="idleTimeout" value="600000" />
            <property name="connectionTimeout" value="60000" />
            <property name="dataSourceProperties">
                <props>
                    <prop key="url">${database.url}</prop>
                    <prop key="user">${database.username}</prop>
                    <prop key="password">${database.password}</prop>
                    <prop key="prepStmtCacheSize">250</prop>
                    <prop key="prepStmtCacheSqlLimit">2048</prop>
                    <prop key="cachePrepStmts">true</prop>
                    <prop key="useServerPrepStmts">true</prop>
                </props>
            </property>
        </bean>

        <bean
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
            id="entityManagerFactory">
            <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
            <property name="persistenceUnitName" value="persistenceUnit" />
            <property name="dataSource" ref="dataSource" />
        </bean>

        <bean class="org.springframework.orm.jpa.JpaTransactionManager"
            id="transactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>

   <tx:annotation-driven transaction-manager="transactionManager" />

</beans>

如何配置此 xml 以添加从属数据源?

【问题讨论】:

    标签: spring jpa entitymanager master-slave hikaricp


    【解决方案1】:

    mysql connector-j documentation中所述指定网址

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 2019-09-03
      • 2018-06-17
      • 2019-07-31
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-08
      相关资源
      最近更新 更多