我有一个要求,我想使用mule配置文件中定义的数据库连接配置。我想在JAVA或Groovy代码中使用它。我该怎么做?
谢谢阿努拉格·库马尔·德维维迪
这取决于您是否正在运行您的 mule 应用程序(MuleContext 存在(,或者您想解析 xml 文件并加载值......假设第一个选项,我只是测试了自己...
骡子 XML 配置文件:
<http:listener-config name="httpConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="muleloadconfigFlow">
<http:listener config-ref="httpConfig" path="/" doc:name="HTTP"/>
<component class="muleloadconfig.MuleLoadConfig" doc:name="Java"/>
</flow>
注意:config-ref="httpConfig">
爪哇类:
public class MuleLoadConfig implements MuleContextAware, Callable {
MuleContext localContext;
@Override
public void setMuleContext(MuleContext context) {
this.localContext = context;
}
public String returnConfigClassName() {
return localContext.getRegistry().get("httpConfig").getClass().toString();
}
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
System.out.println("printing config Class: " + returnConfigClassName());
return "ok";
}}
控制台中的结果:
打印配置类:类org.mule.module.http.internal.listener.DefaultHttpListenerConfig
不确定这是否是您正在寻找的,因为您没有在用例中提供任何详细信息......
希望对您有所帮助!
在java中,你可以这样模式化。
<component>
<singleton-object class="com.alex.v1.jdbc.SQLServerSPExecutor">
<property key="dataSource" value="" value-ref="SData_Source"/>
</singleton-object>
</component>
public class SQLServerSPExecutor implements Callable {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
}
}