2015-04-22 66 views
3

現在,我的API的網址,例如:如何使用Spring MVC對我的API進行版本化?

/api/users 

使用Spring MVC:

@RequestMapping("/api/users") 

我想版本的API:

/api-v1.0/users 

最好是能夠在@RequestMapping註釋中使用SpEL,但it is unfortunately not possible

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

然後有什麼其他的選擇?

+0

1.編碼難。 2.預先處理你的代碼(例如,ant-replace/maven-filter ...)3.擴展DefaultAnnotationHandlerMapping(但不要破壞:) – xerx593

+0

@ sp00m所以你想從屬性文件加載版本? – minion

+0

@minion這將是最好的。 – sp00m

回答

2

@RequestMapping從屬性佔位符值中解析。因此,像下面那樣定義一個PropertySourcesPlaceHolderConfigurer。

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

然後使用下面的語法。

@RequestMapping("/api-${version}/users") 
相關問題