什么是使用stdin-channel-adapter的spring集成类?

时间:2016-07-08 21:16:41

标签: java spring-integration messaging

我很想知道spring集成标记中使用的类,以便通过遍历类的javadoc来获取标记的更多细节。

我有两个基本问题:

  1. spring integration xml标签(例如stdin-channel-adapter)是否转换为<bean class=".." />标签?
  2. 如何找出与spring集成标签关联的bean类?
  3. 以下是spring integration 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 个答案:

答案 0 :(得分:5)

我认为你的第一个问题有些错误。见Andreas&#39;评价。

无论如何,答案就像是。

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负责<stdin-channel-adapter>标记的解析和实例化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