How to set base url for rest in spring boot?

后端 未结 18 2337
日久生厌
日久生厌 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条回答
  •  Happy的楠姐
    2020-11-28 03:56

    Per Spring Data REST docs, if using application.properties, use this property to set your base path:

    spring.data.rest.basePath=/api
    

    But note that Spring uses relaxed binding, so this variation can be used:

    spring.data.rest.base-path=/api
    

    ... or this one if you prefer:

    spring.data.rest.base_path=/api
    

    If using application.yml, you would use colons for key separators:

    spring:
      data:
        rest:
          basePath: /api
    

    (For reference, a related ticket was created in March 2018 to clarify the docs.)

提交回复
热议问题