Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13882

Support default URI prefix for web service @RequestMapping

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 4.2.3, 5.0.1
    • Fix Version/s: None
    • Component/s: Web

      Description

      I had opened a ticket in Spring-Boot on this topic and it was suggested I create one on the Spring JIRA I have added the original ticket as the Reference URL.

      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
      

      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
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              lewisdavidcole David Cole
              Last updater:
              Spring Issues Spring Issues
              Votes:
              6 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 1 week, 4 days ago