有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java热重载上下文数据源

我在Tomcat7服务器上运行spring应用程序,每个客户机都有自己的数据库模式。 所有数据源都是在applicationContext数据源上定义的。xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
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">

<bean id="DataSource" class="es.beyond.conexion.CustomerRoutingDataSource">
    <property name="targetDataSources">
        <map key-type="java.lang.String">
            <entry key="client1" value-ref="client1" />
            <entry key="client2" value-ref="client2" />
        </map>
    </property>
    <property name="defaultTargetDataSource" ref="erpmodularizado" />
</bean>

<bean id="SessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="DataSource" />
    <property name="packagesToScan" value="es.beyond" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<tx:annotation-driven transaction-manager="txManager" />

<bean id="txManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="SessionFactory" />
    <property name="entityInterceptor">
        <bean class="es.beyond.conexion.AuditLogInterceptor" />
    </property>
</bean>

<bean id="client1" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl"
        value="jdbc:mysql://127.0.0.1:3306/client1" />
    <property name="user" value="client1" />
    <property name="password" value="pass" />
    <property name="maxPoolSize" value="100" />
    <property name="maxStatements" value="50" />
    <property name="minPoolSize" value="3" />
    <property name="maxIdleTime" value="30" />
    <property name="preferredTestQuery" value="SELECT 1 FROM dual" />
</bean>

<bean id="client2" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl"
        value="jdbc:mysql://127.0.0.1:3306/client2" />
    <property name="user" value="client2" />
    <property name="password" value="pass" />
    <property name="maxPoolSize" value="100" />
    <property name="maxStatements" value="50" />
    <property name="minPoolSize" value="3" />
    <property name="maxIdleTime" value="30" />
    <property name="preferredTestQuery" value="SELECT 1 FROM dual" />
</bean>

我希望,如果在应用程序中注册了客户机,应用程序将在xml上编写新的模式(我的数据库中还有一个空模式列表要命名),然后在不重新启动tomcat服务器的情况下重新加载de applicationContext

这可能吗?或者我在尝试一些疯狂的东西

谢谢


共 (0) 个答案