【问题标题】:Working example on Spring Mediator in WSO2 ESB 4.6.0WSO2 ESB 4.6.0 中 Spring Mediator 的工作示例
【发布时间】:2013-11-14 17:44:27
【问题描述】:

您好,我正在 WSO2 ESB 4.6.0 中开发 Spring Mediator,使用 thisthis 教程

我收到如下错误:

ERROR - SpringMediator Cannot look up Spring configuration conf/sample/resources/spring/springsample.xml

ERROR - SpringMediatorCannot reference application context with key : conf/sample/resources/spring/springsample.xml

你能解释一下如何解决这个问题吗?

【问题讨论】:

  • 您在运行示例应用程序时遇到此错误,或者您正在处理自己的事情?
  • 嗨 Isuru,首先感谢您的重播。当我运行 Wso2 ESB 文档示例提供的示例应用程序时,您能告诉我如何实现这一目标..
  • 我尝试了示例并在 wso2esb 4.6 中正常工作。您是否正确构建了 axis2 示例?
  • 嗨 Isuru,这是我的 Spring 代理服务,ws.apache.org/ns/synapse" bean="springexample " key="conf/sample/resources/spring/springsample.xml" />,这里我直接使用示例spring示例,我没有构建任何axis2示例..你能解释一下吗。如何做到这一点..
  • 我更新了答案看看

标签: spring wso2 wso2esb wso2carbon synapse


【解决方案1】:

这是因为esb在repository/conf/sample/resources路径下找到了springsample.xml文件

<parameter name="root">file:repository/conf/sample/resources/</parameter>

springsample.xml 文件位置在 repository/samples/resources/ 中。因此应更正如下,

<parameter name="root">file:repository/samples/resources/</parameter>

在文档中,配置不正确,如果您通过命令wso2esb-samples -sn 470 启动esb(如文档中所述),esb 将加载repository/samples/synapse_sample_470.xml 中的文件,在此文件中上述参数已正确配置。

希望这能解决你的问题:)

更新:

根据您的评论,由于您直接使用示例 spring 示例,这是由于文件尝试访问的权限而发生的,或者这可能是由于文件路径错误。所以请尝试使用绝对文件 url。

【讨论】:

  • @Kanchetianeel 我在 git hub 上找不到的 bean 类在哪里
  • 嗨 Isuru,谢谢,这是我的 git Hub url :-gist.github.com/anonymous/7351959 你能检查一下吗..我遇到了示例问题..
  • @Kanchetianeel 我添加了另一个包含完整详细信息的答案。如果您认为正确,请将其标记为答案
【解决方案2】:

我必须按以下方式工作,

该类应扩展 AbstractMediator 并覆盖 mediate() 方法,如下所示,

package com.test.spring.mediator.workingexampleonspringmediator;

import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

public class HelloWorld extends AbstractMediator{

           private String message;   
       public void setMessage(String message){
          this.message  = message;
       }

       public boolean mediate(MessageContext arg0) {

          System.out.println("HELLO "+message);
          return true;
    }
}

然后将jar放到[ESBHOME]/repository/components/lib文件夹中

在中介方法中,它会打印一条带有 HELLO 'arg' 之类参数的消息

我将以下文件添加到注册表(/_system/config/repository/spring/springtest.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN"
        "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans>     
   <bean id="springtest" class="com.test.spring.mediator.workingexampleonspringmediator.HelloWorld"  singleton="false">
   <property name="message"><value>ISURU</value></property>
   </bean>
</beans>

我的代理如下,

<proxy xmlns="http://ws.apache.org/ns/synapse" name="testSpring" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full">
            <property name="START" value="__________________________"/>
         </log>
         <spring:spring xmlns:spring="http://ws.apache.org/ns/synapse" bean="springtest" key="conf:/repository/spring/springtest.xml"/>
         <log level="full">
            <property name="END" value="______________________"/>
         </log>
      </inSequence>
   </target>
   <description></description>
</proxy>

在代理中你可以看到bean=[bean id of the springtest.xml]class=qualified name of the class

在我的 ESB 终端中,我使用 springtest.xml 中的给定属性值输出了以下内容,

[2013-11-07 17:38:30,654]  INFO - LogMediator To: /services/testSpring.testSpringHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:bcae82e9-4027-43c5-bd7a-cbfa885aaf33, Direction: request, START = __________________________, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope>
HELLO ISURU
[2013-11-07 17:38:30,692]  INFO - LogMediator To: /services/testSpring.testSpringHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:bcae82e9-4027-43c5-bd7a-cbfa885aaf33, Direction: request, END = ______________________, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope>

您必须在将 jar 放入 repository/components/lib 后重新启动 ESB

【讨论】:

  • 更多细节在这里http://itsmeisuru.wordpress.com/2013/11/07/wso2-spring-mediator-example/
  • 哦,没关系。我所做的是我添加了一个集合,然后将文件上传到那里。因此,您无需添加 spring 文件夹,只需将其上传到那里,它应该可以工作。我上面提到的博客 [1] 没有 spring 文件夹。 [1]itsmeisuru.wordpress.com/2013/11/07/…
  • @Kanchetianeel madhukaudantha.blogspot.com/2012/07/… 按照上面的链接到第 5 步。然后您应该知道如何将资源(xml 文件)上传到注册表。
  • HI ISURU,非常感谢你的耐心和惊人的天赋,它正在发挥作用,你真的很了不起..
【解决方案3】:

这些是上面 Isuru 解释的 spring 调解器的简要步骤

  1. 通过扩展 AbstractMediator 创建 spring 中介库

  2. 复制到 ESB_HOME/repository/components/lib

  3. 重新启动服务器

  4. 在Registry中注册springtest.xml文件 (http://madhukaudantha.blogspot.com/2012/07/wso2-esb-proxy-from-registry.html Isuru 解释的第 5 步)

  5. 然后,使用 Spring Mediator 创建自定义代理。

在那里, 将 Bean 添加为“springtest”(为 xml 文件中的中介类定义 bean id)

根据第四步选择配置注册表文件存放的Key。

例如:如果您已将该 springtest.xml 文件存储到路径“_system/config/repository/”中
选择 Key 为“/_system/config/repository/springtest.xml”

注意:

  • 在 ESB_HOME/repository/components/dropins 文件夹中验证 OSGI 已创建的 spring 中介库的中介包 被复制到 ESB_HOME/repository/components/lib。如果它不存在 重启服务器后,可能是创建的中介有问题 图书馆。

  • 同时,为中介类放置唯一的包名以避免 与其他中介类冲突 ESB_HOME/repository/components/lib.

  • 请记住为 .xml 文件添加唯一的 bean id 在第 4 步注册 .xml 文件时在注册表中注册。

【讨论】:

    【解决方案4】:

    当我发送消息时,我收到的唯一错误消息就是这个

    ERROR - SpringMediator No bean named 'springtest' is defined
    

    也就是说,配置文件已经找到。但是里面的bean的实例化呢,我看不到任何明确的错误。 jar 文件位于 components/lib 中,我也可以在 dropins 文件夹中看到它。

    :/

    【讨论】:

    • Spring 日志没有重定向到控制台,所以我看不到我的 jar 导出失败。这是 Spring 中不存在的类的实例化问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多