我正在尝试使用从普通java应用程序嵌入的Mule 3.2.1。该应用程序假设在存储空间有限的环境中运行 我尝试了类似的东西(导入,为简洁省略了例外):
DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
ConfigurationBuilder configBuilder = new AutoConfigurationBuilder("mule-config.xml");
MuleContext muleContext = muleContextFactory.createMuleContext(configBuilder);
muleContext.start();
还有这个:
AutoConfigurationBuilder configBuilder = new AutoConfigurationBuilder("mule-config.xml");
DefaultMuleConfiguration configuration = new DefaultMuleConfiguration();
MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
contextBuilder.setMuleConfiguration(configuration);
MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext(configbuilder, contextBuilder);
muleContext.start();
但两者都需要spring-core,spring-beans,spring-context和一些公共库。任何帮助都会很棒。
答案 0 :(得分:2)
如果使用XML配置,则需要Spring。
如果您不想使用Spring,您的选择是:
如果您只想使用原始传输,即不配置任何流或模式,您可以在没有Spring的情况下执行此操作但请记住,如果mule-core
依赖项不能传递Spring,则所有模块和运输。这意味着您必须使用过滤来保持这些依赖性。
例如,要使用HTTP传输,您需要以下Maven依赖项:
<dependency>
<groupId>org.mule</groupId>
<artifactId>mule-core</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-http</artifactId>
<version>3.4.0</version>
<exclusions>
<exclusion>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-spring-config</artifactId>
</exclusion>
</exclusions>
</dependency>
有了这个,你就可以了:
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
MuleContext muleContext = muleContextFactory.createMuleContext(muleContextBuilder);
muleContext.start();
MuleClient client = muleContext.getClient();
MuleMessage response = client.request("http://www.google.com", 20000L);
System.out.println(response.getPayloadAsString());
muleContext.dispose();
System.exit(0);
请注意,如果你正在使用Mule,那么你宁愿直接使用Apache HTTP Client:)
答案 1 :(得分:0)
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
MuleContext muleContext
muleContextFactory.createMuleContext(muleContextBuilder);
muleContext.start();
// create mule client
MuleClient client = new MuleClient(muleContext);
// generate xml request
String reportRequestXml = createXML(reportRequest);
// set up message properties
Map<String, Object> messageProperties = new HashMap<String, Object>();
messageProperties.put("Content-Type", "application/xml");
// send request with timeout
MuleMessage response = client.send(crsRestUrl, reportRequestXml, messageProperties, httpTimeout);
muleContext.stop();