【发布时间】:2016-02-26 22:38:25
【问题描述】:
我正在处理能够在正在运行的 Web 应用程序上动态添加 Spring 集成 httpInbound 侦听器的要求,目前我正在通过以下代码创建一个 HttpRequestHandlingController bean:
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>
但是当我发送请求时,我会在服务器上得到这个:
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
从这篇文章http://duckranger.com/2012/04/spring-mvc-dispatcherservlet/ 我了解到 servlet 在启动时初始化了映射,因为我的监听器的创建可以在 servlet 初始化之后的任何时间发生,我怎样才能让 servlet 刷新并“看到”新的定义,甚至这是正确的方法?嵌入容器是否希望码头更合适?请指教。
【问题讨论】:
标签: spring spring-mvc spring-integration