我有兴趣了解 spring 集成标签中使用的类,以便我可以通过查看类的 javadoc 来获取标签的更多详细信息。
我有两个基本问题:
- 将 spring 集成 xml 标记(例如 stdin-channel-adapter)转换为
<bean class=".." />
标签? - 如何找出与 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>
谢谢
最佳答案
我认为你在第一个问题中有一些错误。请参阅安德烈亚斯的评论。
无论如何,你的答案是这样的。
Spring 中的任何自定义标签都由特定的 NamespaceHandler
处理。 .通常你可以在文件中找到目标实现,如 META-INF/spring.handlers
在特定的 Spring jar 中,例如:
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
关于java - 使用 stdin-channel-adapter 的 spring 集成类是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38275512/