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?

3
  • 1. Code it hard. 2. pre-process your code (e.g. ant-replace/maven-filter...) 3. Extend DefaultAnnotationHandlerMapping (but don't break it:) Commented Apr 22, 2015 at 18:01
  • @sp00m So you want to load the version from property file? Commented Apr 22, 2015 at 18:21
  • @minion This would be the best. Commented Apr 22, 2015 at 20:16

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.