热重载上下文数据源

时间:2017-06-08 12:41:18

标签: java spring tomcat

我的Spring应用程序在Tomcat 7服务器上运行,每个客户端都有自己的数据库模式。 所有数据源都在applicationContext-dataSources.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上写入新架构(我的数据库上还有一个空架构列表要作为对象),然后重新加载de applicationContext而不重启tomcat服务器

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

由于

0 个答案:

没有答案