@RestController
@RequestMapping("/v1")
class Controller {
}
更通用的方法
spring.mvc.servlet.path=/v1
或者
server.servlet.contextPath=/v1
上下文路径是用来访问web应用程序的名称。它是应用程序的根,默认情况下,Spring Boot提供根上下文路径(“/”)上的内容。可以使用属性server.servlet.context-path更改此上下文路径。
另一方面,servlet路径表示主DispatcherServlet的路径。默认值类似于上下文路径,即(“/”),可以通过配置不同的spring.mvc.servlet.path属性进行更改。假设servlet属于servlet上下文,更改上下文路径也会影响servlet路径。
如果您具有以下配置,请记住这两条信息:
server.servlet.context-path=/context-path
spring.mvc.servlet.path=/servlet-path
然后应用程序servlet路径将变为http://localhost:8080/context-path/servlet-path。