How to set base url for rest in spring boot?

后端 未结 18 2364
日久生厌
日久生厌 2020-11-28 03:23

I\'m trying to to mix mvc and rest in a single spring boot project.

I want to set base path for all rest controllers (eg. example.com/api) in a single place (I don\'

18条回答
  •  误落风尘
    2020-11-28 03:54

    Try using a PathMatchConfigurer (Spring Boot 2.x):

    @Configuration
    public class WebMvcConfig implements WebMvcConfigurer  {
    
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.addPathPrefix("api", HandlerTypePredicate.forAnnotation(RestController.class));
        }
    }
    

提交回复
热议问题