3

For now, URLs of my API are for example:

/api/users

With Spring MVC:

@RequestMapping("/api/users")

I would like to version this api:

/api-v1.0/users

The best would be to be able to use an SpEL in the @RequestMapping annotation, but it is unfortunately not possible:

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

What are the other options then?

Community
  • 1
  • 1
sp00m
  • 47,968
  • 31
  • 142
  • 252

2 Answers2

3

Try with @RequestMapping("/api-${version}/users").

See http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-placeholders for more info.

Jose Luis Martin
  • 10,459
  • 1
  • 37
  • 38
2

@RequestMapping resolves from property place holder values. So define a PropertySourcesPlaceHolderConfigurer like below.

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

Then use the syntax like below.

@RequestMapping("/api-${version}/users")
minion
  • 4,313
  • 2
  • 20
  • 35