2

I need to add /api and /stat as my two context paths. I already added /api for the application using server.servlet.context-path=/api.

anuradha151
  • 21
  • 1
  • 4
  • Why do you need to do that?, couldn't you just have the context path / and the two subpaths /api and /stats ? – Javier Toja Aug 05 '21 at 09:28
  • 1
    @karelss. I used subpaths for different services like ```/api/user``` ```/api/content```. These endpoints are using jwt auth mechanism. I need to expose ```/stat``` in basic auth. Can show me a way of doing that. – anuradha151 Aug 06 '21 at 05:40
  • @anuradha151 have u found the solution? I have same problem. Spring Security can config two url pattern to match, with each url pattern, u can use sperate filter to auth. But, in my scenario, I want two context pathes to fit all request mappings in all controllers, security way seems not work. – Feng Oct 27 '22 at 03:21

1 Answers1

2

I think the server.servlet.context-path will affect all your endpoints, but you can specify a different @RequestMapping in each controller class. So if you remove the server.servlet.context-path, you will use the root context path ("/"), and then setting "/api" & "/stat" on your controllers should work.

Eduardo Pérez
  • 488
  • 3
  • 10
  • Thank you for helping me out. But the requirement is to add basic auth endpoints in a new context-path. Currently I use jwt token authentication for ```/api``` endpoints. – anuradha151 Aug 06 '21 at 05:42
  • Maybe this can help with that: https://stackoverflow.com/questions/54706291/spring-multiple-authentication-methods-for-different-api-endpoints – Eduardo Pérez Aug 06 '21 at 09:20