change spring boot 2.0 context-path

2020-07-22 18:22发布

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/

4条回答
做个烂人
2楼-- · 2020-07-22 18:32

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

server.servlet.context-path=/myapp
查看更多
甜甜的少女心
3楼-- · 2020-07-22 18:35

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

查看更多
狗以群分
4楼-- · 2020-07-22 18:36

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
查看更多
迷人小祖宗
5楼-- · 2020-07-22 18:47

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

查看更多
登录 后发表回答