mwnorman
mwnorman

Reputation: 121

Is it possible to support multiple context paths?

I have a Spring Boot app running with application.properties:

server.contextPath=/ctx1

I would like to pick a few specific @Controller's @RequestMappings' and configure them to use a
different contextPath or have them map against the root "/" path

I have looked at @Configuration-ing a ServletRegistrationBean but that doesn't seem to work.

Any help would be greatly appreciated,

Mike

Upvotes: 2

Views: 4885

Answers (1)

Dave Pateral
Dave Pateral

Reputation: 1475

server.contextPath will add url prefix to all controller mappings. You can use @RequestMapping in each controller to add their own mapping for each. Like this:

@RestController
@RequestMapping(path = "/demo")
public class ThinController {

    @RequestMapping(path = "/hello", method = RequestMethod.GET)
    public String hello(){
        return "success...";
    }
}

Upvotes: 3

Related Questions