与休眠一起使用两个数据源的问题? [英] problem with using two datasources with hibernate?

查看:54
本文介绍了与休眠一起使用两个数据源的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打招呼 我试图将两个不同的数据源与hibernate一起使用(两个不同的sessionFactories和两个不同的transactionManagers) 但我发现应用程序无法启动

greeting all I tried to use two different datasources with hibernate (two different sessionFactories and two different transactionManagers ) but I got the application failed to start

它在

Creating new JDBC DriverManager Connection to [jdbc:mysql://some-ip-here/mydb]

这是配置:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <context:component-scan base-package="com.myapp" />
    <context:annotation-config />
    <tx:annotation-driven transaction-manager="transactionManager" />


    <!-- ================PostgreSQL/Hibernate================ -->

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.myapp.domain.myDomain1</value>
            </list>

        </property>

        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
            </value>
        </property>


    </bean>


    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <property name="driverClassName" value="org.postgresql.Driver" />

        <property name="url">
        <value>${db.url}</value> 
        </property>

        <property name="username" > 
        <value>${db.username}</value>
        </property>

        <property name="password">  
        <value>${db.password}</value>
        </property>

    </bean>

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- ================MySQL/Hibernate================ -->

    <bean id="mysqlSessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

        <property name="dataSource" ref="mysqlDataSource" />
        <property name="annotatedClasses">
            <list>
            <value>com.myapp.domain.myDomain2</value>       
            </list>
        </property>

        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.MySQLDialect
            </value>
        </property>
    </bean>


    <bean id="mysqlDataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <property name="driverClassName" value="com.mysql.jdbc.Driver" />

        <property name="url">
        <value>${db.mysql.url}</value> 
        </property>

        <property name="username" > 
        <value>${db.mysql.username}</value>
        </property>

        <property name="password">  
        <value>${db.mysql.password}</value>
        </property>

    </bean>

    <bean id="mysqltransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="mysqlSessionFactory" />
    </bean>

        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />    

        <!-- ================End of MySQL/Hibernate================ -->


</beans>

推荐答案

问题已解决,与远程服务器防火墙有关.

problem fixed, it was with the remote server firewall.

这篇关于与休眠一起使用两个数据源的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆