Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mule 3.3 TCP自定义协议和Spring Injection@Autowired不起作用_Spring_Mule - Fatal编程技术网

Mule 3.3 TCP自定义协议和Spring Injection@Autowired不起作用

Mule 3.3 TCP自定义协议和Spring Injection@Autowired不起作用,spring,mule,Spring,Mule,当我使用自定义tcp协议时,我在Mule中遇到了问题,在自定义协议中有一个使用@Autowired注释的spring依赖注入 CustomProtocol.java public class ContentLengthProtocol extends AbstractByteProtocol{ @Autowired private Adapter adapter; @Lookup("atm-inbound") private ImmutableEndpoint inboundE

当我使用自定义tcp协议时,我在Mule中遇到了问题,在自定义协议中有一个使用@Autowired注释的spring依赖注入

CustomProtocol.java

public class ContentLengthProtocol extends AbstractByteProtocol{
  @Autowired
  private Adapter adapter;

  @Lookup("atm-inbound")
  private ImmutableEndpoint inboundEndpoint;

  public ContentLengthProtocol(){
      super(true);
  }

  public Object read(InputStream is) throws IOException{
    // do some reading
  }
}
Mule配置代码段

<spring:beans>
    <spring:bean id="adapter" class="id.company.dao.Adapter"/>
    <spring:bean id="contentLengthProtocol" class="id.company.protocol.ContentLengthProtocol"/>
</spring:beans>
<tcp:connector name="TCPConnector" validateConnections="true" sendBufferSize="0" receiveBufferSize="1024" receiveBacklog="50" reuseAddress="true" keepAlive="true" clientSoTimeout="0" serverSoTimeout="0" socketSoLinger="0" doc:name="TCPConnector">
    <tcp:custom-protocol ref="contentLengthProtocol"/>
</tcp:connector>
<tcp:endpoint name="tcp-inbound" address="tcp://localhost:1234" connector-ref="TCPConnector" doc:name="TCP"/>
<flow name="AdapterFlow" doc:name="AdapterFlow">
    <tcp:inbound-endpoint ref="tcp-inbound" doc:name="Inbound TCP"/>
    <echo-component doc:name="Echo"/>
</flow>
当流读取ContentLength协议上的输入和处理读取方法时,适配器始终为null。但奇怪的是,如果我只定义ContentLengthProtocolbean,但不将TCP连接器中的bean作为自定义协议引用,spring注入将照常工作,适配器不为null

有人能告诉我这里发生了什么事吗? 任何帮助都将不胜感激。
谢谢。

Mule和Spring注释之间可能存在注入冲突,我认为使用@Inject也不会有帮助

因此,最好采用常规的弹簧注射:

<spring:bean id="contentLengthProtocol"
             class="id.company.protocol.ContentLengthProtocol"
             p:adapter-ref="adapter"
             p:inboundEndpoint-ref="atm-inbound" />

我发现了改变@Autowired进程的确切问题。有一些细节我还没有通知,适配器类实际上是一个包含MyBatis映射器的服务。MyBatis映射器是使用spring MyBatis集成配置的,org.MyBatis.spring.mapper.MapperScannerConfiguration是特定的。此classbean扫描要代理的特定包。不知何故,如果我将这个bean与spring bean和mule结合起来,@Autowired不起作用,即使使用手动将对象注入ContentLengthProtocol也不会正常工作。适配器bean被注入,但适配器bean中的MyBatis mapper类却不能。作为一种变通方法,我使用了一种古老而乏味的方法,即org.mybatis.spring.mapper.MapperFactoryBean,使其工作起来。基本上,必须为我拥有的每个映射器声明这个bean。

嗨,David,我已经尝试过了,但它不起作用。正如上面所说,@Lookup只适用于自定义组件和转换器。但我想要的是将Springbean注入到定制TCP协议中。你还有其他想法吗?好的,我的回答改为建议简单注射而不是自动接线。嗨,大卫,我试过你的解决方案,但没有100%有效。我已经发布了我的答案作为解决方案。无论如何,谢谢你的帮助,它帮助我找到了真正的问题。