Java 如何使用SpringMVC对API进行版本设置?

Java 如何使用SpringMVC对API进行版本设置?,java,spring,api,spring-mvc,version,Java,Spring,Api,Spring Mvc,Version,目前,我的API的URL如下所示: /api/users 使用Spring MVC: @RequestMapping(“/api/users”) 我想将此api的版本设置为: /api-v1.0/users 最好能够在@RequestMapping注释中使用SpEL,但是: @RequestMapping(“/api-#{appProps['version']}/users”) 那么其他选项是什么?尝试使用@RequestMapping(“/api-${version}/users”)

目前,我的API的URL如下所示:

/api/users
使用Spring MVC:

@RequestMapping(“/api/users”)
我想将此api的版本设置为:

/api-v1.0/users
最好能够在
@RequestMapping
注释中使用SpEL,但是:

@RequestMapping(“/api-#{appProps['version']}/users”)

那么其他选项是什么?

尝试使用
@RequestMapping(“/api-${version}/users”)


有关详细信息,请参阅。

@RequestMapping从属性占位符值解析。因此,定义一个PropertySourcesPlaceHolderConfigurer,如下所示

<context:property-placeholder location="classpath*:*.properties"/>

1.编码很难。2.预处理您的代码(例如ant replace/maven filter…)3。扩展DefaultAnnotationHandlerMapping(但不要破坏它:)@sp00m,所以您想从属性文件加载版本?@minion这将是最好的。
@RequestMapping("/api-${version}/users")