Skip to content

Support default URI prefix for web service @RequestMapping #4994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lewisdavidcole opened this issue Jan 21, 2016 · 5 comments
Closed

Support default URI prefix for web service @RequestMapping #4994

lewisdavidcole opened this issue Jan 21, 2016 · 5 comments

Comments

@lewisdavidcole
Copy link

There doesn't seem to be anyway, short of explicitly prefixing each individual @RequestMapping with a default URI like @RequestMapping(path="**/api**/controller1" at the top of the @RestController class, where **/api** is the default. I'm trying to have a clear separation in URL paths between normal application requests and web service requests, allowing me to provide additional security specific to web services.

I have an ongoing StackOverflow post, with no meaningful solution to-date and would like to suggest an enhancement to allow a default URI prefix to be supported somewhere in the Spring Boot application.properties configuration.

http://stackoverflow.com/questions/34801351/how-to-configure-a-default-restcontroller-uri-prefix-for-all-controllers

The result would be, using the example above, that my request mapping would be defined as:

@RequestMapping(path="controller1") 

The resulting URL would resolve to
> /<root_context>/api/controller1

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 21, 2016
@wilkinsona
Copy link
Member

The approach that was suggested on the, now deleted, answer on Stack Overflow should work.

Annotate a base class at the class level with @RequestMapping("/api") and then subclass this controller. As long as you don't have a class-level @RequestMapping on the sub-class, any method-level @RequestMapping will be prefixed with /api.

@lewisdavidcole
Copy link
Author

Interesting. I wasn't aware you could do that. However, that still wouldn't be a great solution for me.
Since I can't have the @RequestMapping on the sub-class, I would have to prefix all method URI's to handle that. I was hoping for more of a 'building block' approach, like:

@RequestMapping(path="/api")
class BaseController{
    ....
}

@RequestMapping(path="sub-class1")
class SubClassedController1 extends BaseController{
   @RequestMapping(path="get-something") 
   public void getSomething(){
       ...
    }
}

@RequestMapping(path="sub-class2")
class SubClassedController2 extends BaseController{
   @RequestMapping(path="get-something") 
   public void getSomething(){
       ...
    }
}

Resulting in
/api/sub-class1/get-something
and
/api/sub-class2/get-something

That seems more natural to me.

@wilkinsona
Copy link
Member

@lewisdavidcole I can certainly see how the behaviour you have described could be useful. Unfortunately, it's pretty much out of Spring Boot's control as it's Spring MVC that defines this behavior and it isn't configurable. Please open a Spring MVC JIRA ticket (https://jira.spring.io/browse/SPR) if you'd like to see this enhancement.

@wilkinsona wilkinsona removed the status: waiting-for-triage An issue we've not yet triaged label Jan 21, 2016
@wilkinsona
Copy link
Member

@jumper10

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants