Skip to content

Reactive auto-configuration not working with Spring Boot 2.2.0 M3 #995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andifalk opened this issue May 23, 2019 · 3 comments
Closed

Reactive auto-configuration not working with Spring Boot 2.2.0 M3 #995

andifalk opened this issue May 23, 2019 · 3 comments
Labels
in: configuration Configuration and setup in: infrastructure Build infrastructure and dependency upgrades resolution: duplicate stack: webflux type: bug

Comments

@andifalk
Copy link

Using Spring HATEOAS 1.0.0 M2 together with Spring Boot 2.2.0 M3 in reactive web mode is not working.
Steps to reproduce this issue:

  1. Configure a new spring project with:
    • Select Java, Spring Boot 2.2.0 M3
    • Select HATEOAS dependency
    • Select WebFlux dependency
  2. Add annotation '@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL, stacks = WebStack.WEBFLUX)'

Then the spring application always starts using Tomcat in Servlet mode.
According to debug mode output the autoconfiguration does not detect a reactive web application:
WebFluxAutoConfiguration:
Did not match:
- not a reactive web application (OnWebApplicationCondition)
Matched:
- @ConditionalOnClass found required class 'org.springframework.web.reactive.config.WebFluxConfigurer' (OnClassCondition)

I tried adding '@EnableWebFlux' annotation, but then another error pops up:
The bean 'requestMappingHandlerAdapter', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration
$EnableWebMvcConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class] and overriding is disabled.

It seems that the Spring HATEOAS dependency always forces a servlet based auto configuration via '@import(HypermediaHttpMessageConverterConfiguration.class)' in class org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration

If I remove the Spring HATEOAS dependency in gradle/maven build file then application starts in reactive mode using netty again as expected.

@odrotbohm
Copy link
Member

Can you clarify whether you have seen this working before? Given the arrangement in Spring Boot's auto-configuration, it looks like nothing in particular has changed for this release. I.e. I am suspecting that some parts of the auto-configuration have always triggered inclusion of configuration that somehow triggers Servlet stuff.

Here's a few things I found out during first level debugging:

  • the HATEOAS starter pulls in the web starter transitively, which probably causes the bootstrap of the servlet infrastructure. This would have to be removed, I guess.

  • if you manually exclude this, Boot will still issue some auto-configuration that depends on some WebMVC stuff:

    Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter
      at org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration$HalMessageConverterSupportedMediaTypesCustomizer.configureHttpMessageConverters (HypermediaHttpMessageConverterConfiguration.java:70)
    

It looks like this will need a bit more refactoring on the Boot side. I'll ping the team and consult them for how to proceed.

@odrotbohm odrotbohm changed the title Reactive support is broken with Spring Boot 2.2.0 M3 Reactive auto-configuration not working with Spring Boot 2.2.0 M3 May 23, 2019
@andifalk
Copy link
Author

Can you clarify whether you have seen this working before? Given the arrangement in Spring Boot's auto-configuration, it looks like nothing in particular has changed for this release. I.e. I am suspecting that some parts of the auto-configuration have always triggered inclusion of configuration that somehow triggers Servlet stuff.

I actually tried this the first time with current Spring Boot 2.2.0 milestone 3, so I cannot tell if it was broken before

Here's a few things I found out during first level debugging:

  • the HATEOAS starter pulls in the web starter transitively, which probably causes the bootstrap of the servlet infrastructure. This would have to be removed, I guess.
  • if you manually exclude this, Boot will still issue some auto-configuration that depends on some WebMVC stuff:
    Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter
      at org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration$HalMessageConverterSupportedMediaTypesCustomizer.configureHttpMessageConverters (HypermediaHttpMessageConverterConfiguration.java:70)
    

That's what I also tried to exclude the servlet web starter dependency then I also got the same error.

It looks like this will need a bit more refactoring on the Boot side. I'll ping the team and consult them for how to proceed.

Thanks very much :-)

@odrotbohm
Copy link
Member

It looks like it hasn't ever worked before. I could get a sample project to bootstrap by explicitly disabling the hypermedia auto-configuration and activating Spring HATEOAS manually:

@EnableAutoConfiguration(exclude = HypermediaAutoConfiguration.class)
@EnableHypermediaSupport(type = HypermediaType.HAL)

There already is a ticket at spring-projects/spring-boot#16020, so I'll close this one in favor of the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: configuration Configuration and setup in: infrastructure Build infrastructure and dependency upgrades resolution: duplicate stack: webflux type: bug
Projects
None yet
Development

No branches or pull requests

2 participants