I'm trying to use HttpRequestHandlerServlet in common with HttpRequestHandlingMessagingGateway to expose simple REST URL to browser. But I cannot register HttpRequestHandlerServlet, I'm doing it in the following way:
@Bean
public ServletRegistrationBean inboundServletRegistration(ApplicationContext context) {
final HttpRequestHandlerServlet servlet = new HttpRequestHandlerServlet();
ServletRegistrationBean registration = new ServletRegistrationBean(
servlet, "/demo/*");
registration.setName("inboundServletRegistration");
return registration;
}
Spring boot application start's ok, but when try to access HttpRequestHandlingMessagingGateway endpoint with mapping:
@Bean
public HttpRequestHandler httpInboundEndPoint() {
// Http Rest gateway expecting reply.
final HttpRequestHandlingMessagingGateway restGateway = new
HttpRequestHandlingMessagingGateway(true);
// Mapping of URL this gateway consumes...
restGateway.setRequestMapping(
mapping(new HttpMethod[]{HttpMethod.GET}, "/context/{param}"));
at address http://localhost:8080/demo/context/{param} I get total nonsense crash:
org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'inboundServletRegistration' must be of type [org.springframework.web.HttpRequestHandler], but was actually of type [org.springframework.boot.context.embedded.ServletRegistrationBean]
Did you come across to this problem? Can you please help me out?
Okay, I figured it out.
Key to pass this problem is to register HttpRequestHandler under the same bean name as the HttpRequestHandlerServlet registration bean...Going rather back to XML config...:-(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With