Mule - make Global Elements more global

寵の児 提交于 2019-12-12 04:35:11

问题


In mule I have many applications running on the same container that access a jdbc connector with the same connection string/user/password set.

Of course any app has configured the same global connector in its xml configuration file, so there is code duplication.

Is there a way to define only once per container the connection and access it from any app?


回答1:


I would try this: have one app create the datasource and store it in JNDI and have the other apps pick it up from JNDI.

Since there is no strong guarantee of app start ordering, it's possible that one app that needs the JNDI datasource would start too soon. You would need to configure Spring to be able to perform the JNDI lookup again in case of failure and configure a threaded retry policy on the Mule JDBC connector.

Also you will need to install the datasource and database JARs in lib/user so all apps could use them.




回答2:


Just create a spring bean for your JDBC connector in xml some where in your system and have all your applications load it in your apps:

   <spring:import resource="JDBC-beans.xml" />

and the xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">

   <!-- Initialization for data source -->
   <bean id="dataSource" 
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://localhost:3306/TEST"/>
      <property name="username" value="root"/>
      <property name="password" value="password"/>
   </bean>

</beans>


来源:https://stackoverflow.com/questions/18915136/mule-make-global-elements-more-global

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!