カスタム 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 ではありません。
誰かがここで何が起こったのか教えてくれませんか? どんな助けでも親切に感謝します。ありがとう。