1

嗨,我正在使用本教程和本教程在 WSO2 ESB 4.6.0开发Spring Mediator

我收到如下错误:

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

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

4

4 回答 4

5

我必须按以下方式工作,

该类应扩展 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

于 2013-11-07T12:27:52.757 回答
2

These are the steps for spring mediator in brief as Isuru explained above

  1. Create spring mediator library by extending AbstractMediator

  2. Copy into ESB_HOME/repository/components/lib

  3. Re-start the server

  4. Register springtest.xml file in the Registry (http://madhukaudantha.blogspot.com/2012/07/wso2-esb-proxy-from-registry.html up to step 5 as Isuru explained)

  5. Then, create a Custom proxy with Spring Mediator.

In there, add Bean as “springtest” (defined bean id for the mediator class within the xml file)

Select the Key as where the configuration registry file stored according to the 4th step.

Ex : If you have stored that springtest.xml file into path “_system/config/repository/”<br> Select Key as “/_system/config/repository/springtest.xml”</p>

Note:

  • Verify in ESB_HOME/repository/components/dropins folder for OSGI bundle of the mediator of the created spring mediator library which is copied into ESB_HOME/repository/components/lib. If it is not there after restarting server, it may be a problem in created mediator library.

  • As well as, put unique package name for the mediator class to avoid conflicts with other mediator class in ESB_HOME/repository/components/lib.

  • Keep in mind to add unique bean id for the .xml file which is registered in the registry when you registered .xml file in 4th step.

于 2013-11-11T09:37:55.907 回答
1

这是因为esbspringsample.xml在路径中找到文件repository/conf/sample/resources

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

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

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

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

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

更新:

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

于 2013-11-06T05:07:52.417 回答
0

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

ERROR - SpringMediator No bean named 'springtest' is defined

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

:/

于 2014-06-23T15:10:38.620 回答