使用两个数据源与hibernate的问题?

时间:2011-01-18 13:31:56

标签: hibernate spring spring-mvc

问候所有人 我试图使用两个不同的数据源与hibernate(两个不同的sessionFactories和两个不同的transactionManagers) 但我得到的应用程序无法启动

它在

的步骤中停止
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>

1 个答案:

答案 0 :(得分:0)

问题已解决,它是远程服务器防火墙。