2016-09-20 62 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添加一個奴隸數據源?

回答