Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 热重新加载上下文数据源_Java_Spring_Tomcat - Fatal编程技术网

Java 热重新加载上下文数据源

Java 热重新加载上下文数据源,java,spring,tomcat,Java,Spring,Tomcat,我在Tomcat7服务器上运行spring应用程序,每个客户机都有自己的数据库模式。 所有数据源都在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/schem

我在Tomcat7服务器上运行spring应用程序,每个客户机都有自己的数据库模式。 所有数据源都在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>

org.hibernate.dialogue.mysql5innodbdialogue
真的

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

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


谢谢

你不会想要的。如果突然重新启动应用程序,应用程序的所有其他用户会发生什么情况。相反,找到另一种方法来持久地存储数据源配置(如在主数据库中),并使用它动态/延迟地配置数据源。写入新的架构文件不会创建新的客户端对象。您必须使用Java代码注册具有新详细信息的新客户端bean。其想法是从webapp的外部文件夹加载applicationContext-dataSources.xml作为资源,以防止在tomcat重新启动时出现此问题@M.Deinum I总是在spring中从xml加载数据源。我怎么能做到?或者我可以在哪里看一个例子?谢谢