在spring应用程序中动态创建HttpRequestHandling
我正在研究能够在运行的web应用程序上动态添加spring integration httpInbound侦听器的需求,目前我正在通过以下代码创建HttpRequestHandlingController bean:在spring应用程序中动态创建HttpRequestHandling,spring,spring-mvc,spring-integration,Spring,Spring Mvc,Spring Integration,我正在研究能够在运行的web应用程序上动态添加spring integration httpInbound侦听器的需求,目前我正在通过以下代码创建HttpRequestHandlingController bean: DefaultListableBeanFactory beanFactory = getBeanFactory(); // first we crate the definition for the connection factor
DefaultListableBeanFactory beanFactory = getBeanFactory();
// first we crate the definition for the connection factory
BeanDefinitionBuilder builder = getBeanBuilderForClass(HttpRequestHandlingController.class);
builder.addConstructorArgValue(true);
builder.addPropertyReference("requestChannel", channelName + "In");
builder.addPropertyReference("replyChannel", channelName + "Out");
builder.addPropertyValue("supportedMethods", methodNames);
builder.addPropertyValue("requestPayloadType", payloadType);
builder.addPropertyReference("messageConverters", "converters");
builder.addPropertyValue("viewName", "jsonView");
builder.addPropertyValue("path", path);
beanFactory.registerBeanDefinition(name, builder.getBeanDefinition());
getLogger().info("HTTP Inbound Gateway succesfully created: " + name);
AbstractEndpoint comp =(HttpRequestHandlingController) getNewContextBeanFactory().getBean(name);
comp.start();
根据日志,似乎一切正常:
INFO inbound-hce-rest-connector - Creating new HTTP Inbound Gateway: inbound-hce-rest-connectorInboundHttp
INFO inbound-hce-rest-connector - HTTP Inbound Gateway succesfully created: inbound-hce-rest-connectorInboundHttp
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'inbound-hce-rest-connectorInboundHttp'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'inbound-hce-rest-connectorInboundHttp'
DEBUG o.s.i.h.i.HttpRequestHandlingController - 'Jaxb2RootElementHttpMessageConverter' was added to the 'defaultMessageConverters'.
DEBUG o.s.i.h.i.HttpRequestHandlingController - 'MappingJackson2HttpMessageConverter' was added to the 'defaultMessageConverters'.
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'inbound-hce-rest-connectorInboundHttp' to allow for resolving potential circular references
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'inbound-hce-rest-connectorConvChannelIn'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'inbound-hce-rest-connectorConvChannelOut'
DEBUG o.s.b.BeanUtils - No property editor [org.springframework.http.HttpMethodEditor] found for type org.springframework.http.HttpMethod according to 'Editor' suffix convention
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'converters'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationGlobalProperties'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'inbound-hce-rest-connectorInboundHttp'
DEBUG o.s.i.h.i.HttpRequestHandlingController - Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling will be supported.
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationEvaluationContext'
DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'inbound-hce-rest-connectorInboundHttp'
INFO o.s.i.h.i.HttpRequestHandlingController - started inbound-hce-rest-connectorInboundHttp
路径是在运行时设置的,在这里您可以看到调试的快照
此外,此上下文运行在此servlet定义之上:
<servlet>
<servlet-name>InboundGCRestServices</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>InboundGCRestServices</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
从本文中,我了解到servlet在开始时初始化映射,因为我的监听器可以在servlet初始化后的任何时候创建,我如何获得servlet刷新并“查看”新定义,甚至这是正确的方法?一个被侵占的集装箱是否希望码头更合适?请注意。您不能在运行时修改
DispatcherServlet
的handlerMappings
我还没有完成,但看起来您可以将detectAllHandlerMappings
设置为false
,编写自己的HandlerMapping
,并使用bean名称HandlerMapping
向上下文添加一个实例
然后可以将新bean添加到自定义处理程序映射类中
您可能可以使用来自
IntegrationRequestMappingHandlerMapping
的逻辑-它是最终的
,因此您不能对它进行子类化。您不能在运行时修改DispatcherServlet
的handlerMappings
我还没有完成,但看起来您可以将detectAllHandlerMappings
设置为false
,编写自己的HandlerMapping
,并使用bean名称HandlerMapping
向上下文添加一个实例
然后可以将新bean添加到自定义处理程序映射类中
您可能可以使用
IntegrationRequestMappingHandlerMapping
中的逻辑-它是最终的
,因此您不能对它进行子类化。谢谢,我将在本周尝试一下,让您知道它是否有效,但非常合理。谢谢,我将在本周尝试一下,让您知道它是否有效,但非常合理
DEBUG o.s.w.s.DispatcherServlet - DispatcherServlet with name 'InboundGCRestServices' processing POST request for [/inbound-grand-central/service/hceServices/processIsoTransaction]
WARN o.s.w.s.PageNotFound - No mapping found for HTTP request with URI [/inbound-grand-central/service/hceServices/processIsoTransaction] in DispatcherServlet with name 'InboundGCRestServices'
DEBUG o.s.w.s.DispatcherServlet - Successfully completed request