Context Path with Webflux

后端 未结 9 1315
借酒劲吻你
借酒劲吻你 2021-02-07 18:52

I\'ve been trying to find a way to set the context path for a webflux application. I know I can configure it using

server.servlet.context-path

9条回答
  •  轮回少年
    2021-02-07 19:22

    Here's my way of doing it with Tomcat Reactive:

    @Configuration
    public class TomcatReactiveWebServerConfig extends TomcatReactiveWebServerFactory {
    
        @Value("${server.servlet.context-path}")
        private String contextPath;
    
        /**
         * {@inheritDoc}
         */
        @Override
        protected void configureContext(final Context context) {
    
            super.configureContext(context);
    
            if (StringUtils.isNotBlank(this.contextPath)) {
                context.setPath(this.contextPath);
            }
        }
    }
    

提交回复
热议问题