2016-09-20 24 views
0

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

另外我该如何建立一个新的实体经理工厂在同一个?

我这配置为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添加一个奴隶数据源?

回答