5
votes

I want to change context path for spring boot 2 for example i want to serve on http://localhost:8080/test/

i mean it not working for me with spring-boot-starter-webflux:2.0.0.RELEASE

it only working with spring-boot-starter-web::2.0.0.RELEASE

I have tried

server.servlet.context-path=/test

But nothing happened to me still serve on url http://localhost:8080/

5
server.servlet.context-path only works with embedded container. How are you deploying your application ? - Kedar Joshi
it work with me on spring-boot-starter-web - ashraf revo
but not working for spring-boot-starter-webflux - ashraf revo
This is logical as webflux uses netty instead of a servlet container so I doubt properties in namespace server.servlet.* applies to webflux. - Kedar Joshi

5 Answers

11
votes

If you use the servlet API then the property is now called

server.servlet.context-path=/myapp
7
votes

As confirmed by Andy Wilkinson @andy-wilkinson of the Spring Boot team via Gitter

There’s no concept of context path in WebFlux so there’s no equivalent property

i.e WebFlux doesn't support context path configuration

3
votes

In spring boot 2.3.x you can set spring.webflux.base-path property

spring.webflux.base-path=/path
1
votes

For use cases where WebFlux application is behind load balancer/proxy you can use dedicated class - ForwardedHeaderTransformer that will extract path context from X-Forwarded-Prefix and will add it to ServerHttpRequest.

Doing so you won't need to modify global context-path (which does not make sense in WebFlux)

More about it here: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-web-handler-api

1
votes

In reference to Spring Boot 2.x. below configuration apply for application.yml

server:
  port: 8080
  servlet:
    context-path: /test

For application.properties configuration are

server.port=8080
server.servlet.context-path= /test