Eug*_*kov 5 java spring spring-integration
当我使用 spring 文档中描述的配置时:
\n\n@Configuration\n@EnableIntegration\npublic class MyFlowConfiguration {\n\n @Bean\n @InboundChannelAdapter(value = "inputChannel", poller = @Poller(fixedDelay = "1000"))\n public MessageSource<String> consoleSource() {\n return CharacterStreamReadingMessageSource.stdin();\n }\n\n @Bean\n @Transformer(inputChannel = "inputChannel", outputChannel = "httpChannel")\n public ObjectToMapTransformer toMapTransformer() {\n return new ObjectToMapTransformer();\n }\n\n @Bean\n @ServiceActivator(inputChannel = "httpChannel")\n public MessageHandler httpHandler() {\n HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://foo/service");\n handler.setExpectedResponseType(String.class);\n handler.setOutputChannelName("outputChannel");\n return handler;\n }\n\n @Bean\n @ServiceActivator(inputChannel = "outputChannel")\n public LoggingHandler loggingHandler() {\n return new LoggingHandler("info");\n }\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我可以使用哪种 bean 定义名称来到达端点?\n当通过组件使用配置时,文档中提供了信息:
\n\n\n\n\n这些注释的处理会创建与类似 xml 组件相同的 beans(AbstractEndpoints 和 MessageHandlers(或入站通道适配器的 MessageSources - 见下文))。bean 名称使用以下模式生成:[componentName].[methodName].[decapitalizedAnnotationClassShortName ] 代表 AbstractEndpoint,并且与 MessageHandler (MessageSource) bean 的名称相同,附加 .handler (.source) 后缀。MessageHandler (MessageSource) 也有资格被第 8.2 节 \xe2\x80\x9cMessage History\xe2 跟踪\x80\x9d。
\n
但这里怎么用它呢?
\n如果我理解正确的话,您想将其中一些端点注入到您的服务中。不确定“为什么?”,但可以这样做(例如为此httpHandler):
@Autowire
@Qualifier("myFlowConfiguration.httpHandler.serviceActivator")
private AbstractEndpoint httpEndpoint;
Run Code Online (Sandbox Code Playgroud)
根据上述规则:
myFlowConfiguration- 包含带有 的方法的类的 bean 名称@ServiceActivator。就你而言,这是你的@Configuration
httpHandler方法名称与@ServiceActivator
serviceActivator- 的首字母缩写名称@ServiceActivator。
明白了吗 ?
更新
我不使用 xml 上下文,只使用基于 java 的配置,所以答案是
@Import
好的,谢谢。这就是一个答案。任何@Import @Configuration都带有带有完全限定类名的 bean 名称,包括包(来自ConfigurationClassPostProcessor):
/* using fully qualified class names as default bean names */
private BeanNameGenerator importBeanNameGenerator = new AnnotationBeanNameGenerator() {
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
return definition.getBeanClassName();
}
};
Run Code Online (Sandbox Code Playgroud)
因此,如果我们要使用这些类中对端点的引用,我们必须记住这一点unnamed。
当然,为了简化你的生活,你可以添加一个name到你的MyFlowConfiguration:
@Configuration("myFlowConfiguration")
@EnableIntegration
public class MyFlowConfiguration {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1045 次 |
| 最近记录: |