Context Path with Webflux

后端 未结 9 1180
借酒劲吻你
借酒劲吻你 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

    You can use web Filter, as mentioned in above answers, but you can do one more thing. Write a Base Controller and Extend every class to that Base Controller. For example:

    Base Controller.java

    @RestController
    @RequestMapping("/{base_url}")
    public abstract class BaseController {
    }
    

    NewController.java

    @RestController
    public class NewController extends BaseController{
      @Autowired
      DatabaseClient databaseClient;
    
      @GetMapping("/status")
      public Mono> status() {
        return databaseClient.execute("SELECT 'ok'").
          map(row -> singletonMap("status", row.get(0, String.class)))
          .one();
      }
    }
    

    So now you can hit /{base_url}/status

提交回复
热议问题