Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot register HttpRequestHandlerServlet with Spring Boot

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?

like image 972
Tomas Kloucek Avatar asked Feb 22 '26 19:02

Tomas Kloucek


1 Answers

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...:-(

like image 69
Tomas Kloucek Avatar answered Feb 24 '26 11:02

Tomas Kloucek