java - 将 Spring xml 配置转换为 java
问题描述
我在春季有一个用于邮件服务的 XML 配置,我想将其转换为 JAVA 配置。
XML 看起来像这样
<int:chain id="chain"
input-channel="outMailError"
output-channel="outMailEntry">
<int:poller max-messages-per-poll="1" fixed-rate="20000" />
<int:transformer ref="mailSendErrorTransformer" />
</int:chain>
<int:channel id="outMailError">
<int:queue capacity="500" />
</int:channel>
<int:channel id="outboundMailEntry" />
我能够将频道转换为
@Bean
public DirectChannel outboundMailEntry() {
return new DirectChannel();
}
@Bean
public QueueChannel outboundMailErrorChannel() {
return new QueueChannel(500);
}
但我不知道如何为 int:chain 做同样的事情。我能够调试并找出 spring 为 xml 的“链”部分实例化什么类型的 bean - 它PollingConsumer
需要 2 个参数PollableChannel inputChannel, MessageHandler handler
。
第一个不是问题,因为我已经有了,它是
@Qualifier("outMailError")
QueueChannel channel
但我不知道第二个... Spring 本身初始化了一些MessageHandlerChain
,但我无法设置outMailEntry
它,也不知道轮询器和变压器.. 有什么想法吗?
解决方案
chain
Java Config中没有等价物。它是专为 XML 设计的,可以最大限度地减少 XML 编码。
另一方面,看起来你根本不需要那个<chain>
:你那里只有一个<int:transformer>
。
在 Java Config 中,您将在方法上使用具有适当和属性的@Trasnoformer
注释。等价物也在那里作为具有切除配置的属性存在。mailSendErrorTransformer
inputChannel
outputChannel
<int:poller>
poller
@Poller
从这里开始查看文档中的更多信息: https ://docs.spring.io/spring-integration/docs/current/reference/html/overview.html#configuration-enable-integration
推荐阅读
- java - Query Elastic DSL - 使用 Spring Boot 数据进行搜索查询
- python - 带有 python 请求的 Docker 命令
- azure-devops - Azure Devops 中的单个团队是否可以有多个积压工作?
- google-cloud-platform - 谷歌云防火墙
- javascript - b-card-img-lazy 未在未找到图像上触发错误事件
- javascript - 向对象添加新字段时遇到问题
- audiokit - Audiokit:(V5)音序器无法在轨道的同一位置同时播放音符
- java - 保存 ImageView 背景状态
- python - 基维不工作。[CRITICAL] [Window] 找不到任何有价值的 Window 提供程序
- javascript - 如何在反应中并排放置两个输入字段