如何在春季启动时设置基本网址? [英] How to set base url for rest in spring boot?
问题描述
我正在尝试在一个弹簧启动项目中混合使用mvc和rest。
I'm trying to to mix mvc and rest in a single spring boot project.
我想为所有其他控制器设置基本路径(例如。 com / api)
在一个地方(我不想用 @RequestMapping('api / products')
注释每个控制器,而只是 @RequestMapping('/ products')
。
I want to set base path for all rest controllers (eg. example.com/api)
in a single place (I don't want annotate each controller with @RequestMapping('api/products')
, instead, just @RequestMapping('/products')
.
可以通过example.com/whatever访问Mvc控制器
Mvc controllers should be accessable by example.com/whatever
有可能吗?
(我不使用spring数据休息,只是spring mvc)
(I don't use spring data rest, just spring mvc)
推荐答案
使用Spring Boot 1.2+,它只需要application.properties中的一个属性:
With Spring Boot 1.2+, all it takes is a single property in application.properties:
spring.data.rest.basePath=/api
这篇关于如何在春季启动时设置基本网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!