有人可以给我简单的弹簧与m子整合吗? [英] Can someone give me simple spring integration with mule?

查看:74
本文介绍了有人可以给我简单的弹簧与m子整合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spring项目与Mule和a集成在一起,在启动时遇到错误.我有什么最好的参考资料可以用于弹簧m子的全流程集成吗?

I am integrating a spring project with Mule and a, getting below error in startup. Is there any best reference I can use for spring mule integration with a full flow?

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
    xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.7.0"
    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-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">


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

    <file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" />
    <mulexml:jaxb-context name="JAXB_Context" packageNames="com.dbs.ibgt.scf.eventhandler" doc:name="JAXB Context" />

    <flow name="Push  Transactions to IMEX">
        <file:inbound-endpoint responseTimeout="10000" doc:name="File" path="D:\SCF\eh_in" />
        <mulexml:jaxb-xml-to-object-transformer jaxbContext-ref="JAXB_Context" doc:name="XML to JAXB Object" returnClass="com.eventhandler.EventHandlerMessage" />
        <set-session-variable variableName="jaxbObject" value="#[payload]" doc:name="Set the Jaxb Object" />

    <component>
      <spring-object bean="EventChecker">
            <property-entry-point-resolver property = "checkEvent" />
      </spring-object>
    </component>

        <logger level="INFO" doc:name="Logger" message="message=&quot;#[message.payload]&quot;" />
    </flow>

</mule>

Java文件

@Component
public class EventChecker {

    public String checkEvent()
    {
        System.out.println("Inside Check Event");
        return "SEND_IMEX";
    }
}

错误堆栈.....

INFO:初始化Spring根WebApplicationContext org.mule.api.config.ConfigurationException:XML文档中的第35行 来自URL [文件:/D:/Work/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/...../WEB-INF/classes/EventHandler.xml] 是无效的;嵌套的异常是org.xml.sax.SAXParseException; lineNumber:35; columnNumber:66; cvc-complex-type.2.4.a:无效 找到内容以element开头 属性入口点解析器".之一 '{" http://www.mulesoft.org/schema/mule/core " :财产, " http://www.mulesoft.org/schema/mule/core ":属性}' 是期待. (org.mule.api.lifecycle.InitialisationException)在 org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:49) 在 org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) 在 org.mule.context.DefaultMuleContextFactory $ 2.configure(DefaultMuleContextFactory.java:103) 在 org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:217) 在 org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:98) 在 org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:57) 在 com.dbs.ibgt.scf.startup.MuleStartup.contextInitialized(MuleStartup.java:57) 在 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 在 org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559) 在 org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549) 在java.util.concurrent.FutureTask.run(FutureTask.java:262)在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 在 java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615) 在java.lang.Thread.run(Thread.java:745)

INFO: Initializing Spring root WebApplicationContext org.mule.api.config.ConfigurationException: Line 35 in XML document from URL [file:/D:/Work/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/...../WEB-INF/classes/EventHandler.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 66; cvc-complex-type.2.4.a: Invalid content was found starting with element 'property-entry-point-resolver'. One of '{"http://www.mulesoft.org/schema/mule/core":property, "http://www.mulesoft.org/schema/mule/core":properties}' is expected. (org.mule.api.lifecycle.InitialisationException) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:49) at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) at org.mule.context.DefaultMuleContextFactory$2.configure(DefaultMuleContextFactory.java:103) at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:217) at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:98) at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:57) at com.dbs.ibgt.scf.startup.MuleStartup.contextInitialized(MuleStartup.java:57) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

推荐答案

Jeba,我有一个适合您要求的模板:

Jeba, I have a template for your requirement :

https://github.com/jrichardsz/mule-esb-usefull-templates

该项目包含一个简单的spring组件,并展示了如何在mule应用中使用它.

This project contains a simple spring component and shows how use it in mule app.

还显示了如何同时读取属性文件和处理m子消息.

Also shows how read a properties file and handle mule message at the same time.

结构:

mule-project\pom.xml
mule-project\README.md
mule-project\src
mule-project\src\main
mule-project\src\test
mule-project\src\main\app
mule-project\src\main\java
mule-project\src\main\resources
mule-project\src\main\app\mule-app.properties
mule-project\src\main\app\mule-deploy.properties
mule-project\src\main\app\spring-mule.xml
mule-project\src\main\java\com
mule-project\src\main\java\com\spring
mule-project\src\main\java\com\spring\component
mule-project\src\main\java\com\spring\component\SearchAuthor.java
mule-project\src\main\resources\app-spring-component.xml
mule-project\src\main\resources\app-spring-context.xml
mule-project\src\main\resources\app.properties
mule-project\src\test\java
mule-project\src\test\resources
mule-project\src\test\java\.keep
mule-project\src\test\resources\.keep

M子应用程序:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.6/mule-stdio.xsd">

    <spring:beans>
        <spring:import
            resource="classpath*:/app-spring-context.xml" />        
        <spring:import
            resource="classpath*:/app-spring-component.xml" />      
    </spring:beans>

    <stdio:connector name="stdioConnector" messageDelayTime="1234"
           outputMessage="abc" promptMessage="Ingrese el nombre del libro : "
           promptMessageCode="456"
           doc:name="STDIO"/>

    <flow name="spring-muleFlow">

        <stdio:inbound-endpoint  system="IN" connector-ref="stdioConnector" doc:name="STDIO"/>
        <logger message="Search book : #[payload]" level="INFO" doc:name="Logger"/>

        <component doc:name="searchAuthor">
            <spring-object bean="searchAuthor" />
        </component>
        <logger message="Show Results : #[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

弹簧组件:

package com.spring.component;

import java.util.Map;

import javax.annotation.Resource;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("searchAuthor")
@Scope("prototype")

/*
 * Use Callable if you want : 
 * (spring functionalities, handle mule message and read a properties file) 
 * at the same time.
 * 
 * This is what you will use more.
 * 
 * If you need only spring, dont use : implements Callable
 * 
 * */
public class SearchAuthor implements Callable{

//  @Autowired
//  private AnotherSpringComponetOrServiceOrWhatever spring;    

    @Resource(name="app") //app is the id="app" app-spring-context.xml
    protected Map<String,String> propertiesApp; 

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {

        String payload = (String) eventContext.getMessage().getPayload();

        return String.format("This book [%s] was made by : %s", payload, propertiesApp.get("by"));
    }

}

Spring xml配置:

app-spring-context.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"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-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">

    <!--general spring configurations-->
    <context:annotation-config />   

    <util:properties id="app" location="classpath:app.properties"/>
    <context:property-placeholder properties-ref="app" ignore-resource-not-found="true"/>

    <context:component-scan base-package="com.spring.component"/>


</beans>

app-spring-component.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" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-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">

    <!-- import objects that have not been scanned or another spring functionalities -->

    <!-- <bean ... -->

</beans>

希望这对您有所帮助.

致谢.

这篇关于有人可以给我简单的弹簧与m子整合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆