如何在春季启动时设置基本网址? [英] How to set base url for rest in spring boot?

查看:128
本文介绍了如何在春季启动时设置基本网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个弹簧启动项目中混合使用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

参考链接: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#getting-started.changing-base-u ri

这篇关于如何在春季启动时设置基本网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆