【问题标题】:what are the spring integration classes used stdin-channel-adapter?使用 stdin-channel-adapter 的 spring 集成类是什么?
【发布时间】:2016-11-11 13:05:19
【问题描述】:

我有兴趣了解 spring 集成标签中使用的类,以便通过类的 javadoc 获得标签的更多详细信息。

我有两个基本问题:

  1. spring 集成 xml 标签(例如 stdin-channel-adapter)是否转换为<bean class=".." /> 标签?
  2. 如何找出与spring集成标签关联的bean类?

这里是一个简单的spring集成xml上下文文件示例:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.0.xsd
        http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-4.0.xsd">


<int-stream:stdin-channel-adapter id="producer" channel="messageChannel" />
<int:poller id="defaultPoller" default="true" max-messages-per-poll="2" fixed-rate="100" />

<int-stream:stdout-channel-adapter id="consumer" channel="messageChannel" append-newline="true" /> 

<int:channel id="messageChannel" /> 

</beans>

谢谢

【问题讨论】:

  • 1) “标签会转换成标签吗?” 呃,什么?!? --- 2) 运行代码,然后从bean factory获取bean,看看是什么。它被称为empirical evidence(通过观察获得的知识)。
  • 1) 抱歉,这是格式问题。我更新了问题以更清楚地说明问题。 2)您的解决方案是一种方法。谢谢。

标签: java spring-integration messaging


【解决方案1】:

我认为你的第一个问题有一些错误。请参阅 Andreas 的评论。

反正你的答案是这样的。

Spring 中的任何自定义标签都由特定的NamespaceHandler 处理。通常,您可以在特定 Spring jar 中的 META-INF/spring.handlers 等文件中找到目标 impl,例如:

http\://www.springframework.org/schema/integration/stream=org.springframework.integration.stream.config.StreamNamespaceHandler

你可以找到如下代码:

this.registerBeanDefinitionParser("stdin-channel-adapter", new ConsoleInboundChannelAdapterParser());

您可以在哪里确定 ConsoleInboundChannelAdapterParser 负责解析和实例化 &lt;stdin-channel-adapter&gt; 标记的 bean。

在那里你可以找到如下代码:

BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
            "org.springframework.integration.stream.CharacterStreamReadingMessageSource");

所以,目标 bean 实例的真正类是 CharacterStreamReadingMessageSource。但这还不是全部。

请在此处查找设计和型号:http://docs.spring.io/spring-integration/docs/4.3.0.RELEASE/reference/html/overview.html#programming-tips

【讨论】:

  • 很好的解释,这就是我想要的。谢谢。
猜你喜欢
  • 2016-11-26
  • 1970-01-01
  • 2014-12-24
  • 1970-01-01
  • 1970-01-01
  • 2016-10-28
  • 1970-01-01
  • 1970-01-01
  • 2016-01-27
相关资源
最近更新 更多