How do I version my API with Spring MVC?

Now my API urls are:

/api/users

      

With Spring MVC:

@RequestMapping("/api/users")

      

I would like to change this api:

/api-v1.0/users

      

Your best bet would be to use SpEL in annotation @RequestMapping

, but unfortunately this is not possible :

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

      

What are the other options?

+3


source to share


2 answers


@RequestMapping resolves from place owner values. Therefore, define PropertySourcesPlaceHolderConfigurer as shown below.

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

      



Then use the syntax as shown below.

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

      

+2


source


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 details .

+3


source







All Articles