我在我的项目中使用了正在运行的Mule应用程序。我想要做的是添加一些组件,每次启动Mule服务器时清除一些数据库表。
在这件事上使用的组件是什么?我希望它是从XML发生的,而不是我必须编写的一些Java组件(JDBC等)
谢谢!
答案 0 :(得分:5)
完成:
这是配置:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/3.2/mule-jdbc.xsd
">
<spring:beans>
<spring:bean id="jdbcDataSource" class="org.hsqldb.jdbc.JDBCDataSource">
<spring:property name="url" value="jdbc:hsqldb:mem:test-db" />
</spring:bean>
<lang:groovy id="dataInitializer">
<lang:inline-script><![CDATA[
import org.mule.api.context.notification.*;
import org.mule.context.notification.*;
import org.mule.module.client.MuleClient;
class DataInitializer implements MuleContextNotificationListener<MuleContextNotification> {
public void onNotification(MuleContextNotification notification) {
if (notification.action == MuleContextNotification.CONTEXT_STARTED)
new MuleClient(notification.muleContext).dispatch("jdbc://initialDataPurge", null, null)
}
}
]]></lang:inline-script>
</lang:groovy>
</spring:beans>
<notifications>
<notification event="CONTEXT"/>
<notification-listener ref="dataInitializer"/>
</notifications>
<jdbc:connector name="jdbcConnector" dataSource-ref="jdbcDataSource">
<jdbc:query key="initialDataPurge" value="DELETE FROM test;" />
</jdbc:connector>
</mule>