1

カスタム tcp プロトコルを使用していたときに Mule で問題が発生し、カスタム プロトコル内に @Autowired アノテーションを使用したスプリング依存性注入があります。

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>

フローが ContentLengthProtocol で入力を読み取り、メソッドを処理する場合、アダプターは常に null です。しかし、奇妙なことに、ContentLengthProtocol Bean を定義するだけで、TCP コネクタ内の Bean をカスタム プロトコルとして参照していない場合、スプリング インジェクションは通常どおり機能し、アダプターは null ではありません。

誰かがここで何が起こったのか教えてくれませんか? どんな助けでも親切に感謝します。ありがとう。

4

2 に答える 2

0

プロセスを変更する正確な問題を見つけました@Autowired。お知らせしていない詳細がいくつかありますが、 Adapter クラスは、実際には MyBatis マッパーを保持するサービスです。MyBatis マッパーは、具体的には spring-mybatis 統合を使用して構成さorg.mybatis.spring.mapper.MapperScannerConfigurerれます。このクラス (bean) は、プロキシされる特定のパッケージをスキャンします。どういうわけか、この Bean を Spring Bean および Mule と組み合わせると、@Autowired が機能せず、<property>オブジェクトを手動で注入するために使用してもContentLengthProtocol正しく機能しません (アダプター Bean は注入されますが、アダプター Bean 内の MyBatis マッパー クラスは注入されません)。 . 回避策として、古くて退屈な方法であるorg.mybatis.spring.mapper.MapperFactoryBeanBean を使用してなんとか動作させることができました。基本的に、この Bean は、私が持っているマッパーごとに宣言する必要があります。

于 2012-09-24T17:34:46.773 に答える
0

Mule アノテーションと Spring アノテーションの間でインジェクションの競合が発生する可能性があります。doc によると、使用しても役に立たないと思い@Injectます。

したがって、通常の Spring インジェクションを使用する方がよいでしょう。

<spring:bean id="contentLengthProtocol"
             class="id.company.protocol.ContentLengthProtocol"
             p:adapter-ref="adapter"
             p:inboundEndpoint-ref="atm-inbound" />
于 2012-09-20T16:51:11.880 に答える