Spring+Hibernate+Proxool兩個資料庫連線池配置
阿新 • • 發佈:2019-02-19
1,配置兩個proxool.xml檔案,proxool.first.xml配置
<proxool>
<alias>Proxool.First</alias>
<proxool>
<alias>Proxool.Second</alias>
2,配置兩個hibernate.xml檔案,hibernate.first.xml配置
<session-factory> <property name="hibernate.proxool.pool_alias"> Proxool.First </property> <property name="hibernate.connection.provider_class"> org.hibernate.connection.ProxoolConnectionProvider </property> <property name="hibernate.proxool.xml"> WEB-INF/classes/proxool.first.cfg.xml </property>
hibernate.second.xml配置類推。
3,寫兩個HibernateSessionFactory.java,唯一的區別,載入不同的hibernate.xml檔案。
public class FirstSessionFactory {
private static String CONFIG_FILE_LOCATION = "/hibernate.first.cfg.xml";
4,ApplicationContext.xml配置
<bean id="dataSourceFirst" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>org.logicalcobwebs.proxool.ProxoolDriver</value> </property> <property name="url"> <value>Proxool.First</value> </property> </bean> <bean id="dataSourceSecond" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>org.logicalcobwebs.proxool.ProxoolDriver</value> </property> <property name="url"> <value>Proxool.Second</value> </property> </bean> 5,web.xml配置 <servlet> <servlet-name>FirstServletConfigurator</servlet-name> <servlet-class> org.logicalcobwebs.proxool.configuration.ServletConfigurator </servlet-class> <init-param> <param-name>xmlFile</param-name> <param-value> WEB-INF/classes/proxool.first.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>SecondServletConfigurator</servlet-name> <servlet-class> org.logicalcobwebs.proxool.configuration.ServletConfigurator </servlet-class> <init-param> <param-name>xmlFile</param-name> <param-value> WEB-INF/classes/proxool.second.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 6,程式碼中呼叫不同的連線池 Session session = SecondSessionFactory.getSession();