spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.39k stars 40.51k forks source link

Support DevTools remote update in reactive web applications #13092

Open ashirman opened 6 years ago

ashirman commented 6 years ago

Hello,

I am creating spring-boot application (version 2.0.1.RELEASE) using kotlin (1.2.41), java 8 (Oracle's JDK 1.8.0.172) and webflux provided by boot:spring-boot-starter-webflux starter. The application entry point looks like following

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
    val springApplication = SpringApplication(DemoApplication::class.java)
    springApplication.webApplicationType = WebApplicationType.REACTIVE

    springApplication.run()
}

it works fine from webflux stack perspective but it does not allow to use any functionality from spring-boot-devtools and Remote Update in particular. I've detected that devtools-related beans such as DispatcherFilter, UrlHandlerMapper, HttpRestartServerHandler etc were registered successfully in the context but the only issue is that webcontext of embedded tomcat is not aware of them at all. So, even filter bean was registered in the context it is not a part of embedded tomcat servlet context and it does not receive any incoming requests.

Need to note that I am aware of completely different conception of webflux/reactive flow comparing to old-way servlets/filtes flow. But at the same time I see no reason not to have devtools available within REACTIVE web application type. Please correct me if I am wrong.

Here is an example how it was possible to run devtools using TomcatReactiveWebServerFactory (was inspired mostly by this approach https://stackoverflow.com/a/48790976)

@Configuration
public class RemoteDevToolConf {

    @Autowired
    DispatcherFilter remoteDevToolsDispatcherFilter;

    @Bean
    public WebServerFactoryCustomizer<TomcatReactiveWebServerFactory> customizer() {

        return factory -> factory.addContextCustomizers(
                context -> {
                    context.addFilterDef(remoteToolFilterDefinition());
                    context.addFilterMap(devToolFilterMapping());
                }
        );
    }

    @NotNull
    private FilterDef remoteToolFilterDefinition() {
        FilterDef filterDef = new FilterDef();
        filterDef.setFilterName("remoteDevToolsDispatcherFilter");
        filterDef.setFilter(remoteDevToolsDispatcherFilter);
        return filterDef;
    }

    @NotNull
    private FilterMap devToolFilterMapping() {
        FilterMap filterMap = new FilterMap();
        filterMap.setFilterName("remoteDevToolsDispatcherFilter");
        filterMap.addURLPattern("/*");
        return filterMap;
    }
}

Well, after such a workaround (mostly because it works fine with tomcat and won't work fine with netty where we can't customise servlet context in a such way AFAIK) remote restart works fine and a URI .~~spring-boot!~/restart is available for clients.

My questions are following:

  1. Any reasons why spring-boot-devtools doesn't work out of the box with REACTIVE application context? Having said that is it an issue or explicitly defined behaviour?
  2. Any drawbacks in usage of devtools filters in a provided manner (ignoring the fact that it works fine with tomcat only so it can be handled by @ConditionalOn from what I feel)?
wilkinsona commented 6 years ago

Any reasons why spring-boot-devtools doesn't work out of the box with REACTIVE application context? Having said that is it an issue or explicitly defined behaviour?

I suspect it was an oversight when WebFlux support was added in 2.0. DevTools remote update functionality isn't that widely used as far as we know.

Any drawbacks in usage of devtools filters in a provided manner

I'm not sure as I'm not sufficiently familiar with how WebFlux integrates with Tomcat other than knowing that it builds on top of Servlet's async support. @bclozel may be able to tell us more.

To support this across all four container we would need WebFlux equivalents of much of the code in org.springframework.boot.devtools.remote.server which is currently Servlet-specific. I guess we need to decide if it's worth the effort or if we should document this as a limitation.

ChiragMoradiya commented 2 years ago

I was trying to use remote devtools with webflux app. After spending a considerable amount of time I came to know that this issue is still open.

Please, share whether any plan to support this in near future?

wilkinsona commented 2 years ago

Sorry for the wasted time, @ChiragMoradiya. I've opened https://github.com/spring-projects/spring-boot/issues/28955 to make sure that we've clearly documented that using DevTools with a remote application is not supported with WebFlux.

I'm sure you were frustrated so thank you for asking nicely about the status of this issue. This issue is assigned to the General Backlog. That means that it's something that we'd like to do at some point, but we do not have any concrete plans to do so. We have a number of other higher priority items on our plates at the moment so I'm afraid that it's unlikely that we'll get to this one any time soon.

ChiragMoradiya commented 2 years ago

@wilkinsona Thank you for the prompt reply!

No problem. I understand and respect your priority schedule. Yes, documenting the fact will help others to discover this in advance.

ferrerogg commented 1 month ago

Any update on this feature? It would be great to enable remote devtools for hot reload with docker build image and reactive applications

wilkinsona commented 1 month ago

@ferrerogg please see above. Any updates will appear as comments and/or a change to the assigned milestone.