0

I have Spring Boot app and the following Controller

@Controller
@RequestMapping("/orders/{id}")
@ExposesResourceFor(Payment.class)
@RequiredArgsConstructor
public class PaymentController {
    ...
}

When I change

spring.data.rest.base-path=/api

then Controller reacts to requests without /api base path

curl -i -X PUT -H "Content-Type:application/json" -d "{ \"number\": \"1234123412341234\" }" http://localhost:8080/orders/1/payment

i.e. not http://localhost:8080/api/orders/1/payment

If I want to have /api base path, this would mean updating controller mapping to @RequestMapping("/api/orders/{id}") which is not desirable because I hardcode configuration into code.

Is there any solution to this problem? Thanks

Patrik Mihalčin
  • 3,341
  • 7
  • 33
  • 68
  • That property is for Spring Data Rest controllers. Your controller is a standard Spring MVC constroller. See here for further discussion: http://stackoverflow.com/questions/32927937/how-to-set-base-url-for-rest-in-spring-boot – Alan Hay Apr 21 '17 at 15:53

2 Answers2

4

And some remark:

Do NOT use class-level @RequestMapping annotation if you use @RepositoryRestController annotation.

Otherwise your controller methods could be mapped twice !

First by RequestMappingHandlerMapping WITHOUT the basePath, then by the RepositoryRestHandlerAdapter WITH the basePath

Selindek
  • 3,269
  • 1
  • 18
  • 25
3

To make your custom controllers aware of the base path configured you have to annotate them with @RepositoryRestController instead of @Controller

Mathias Dpunkt
  • 11,594
  • 4
  • 45
  • 70