0

New to spring and have a question regarding setting the Rest URI path.

I have a working rest service and I would like to change the URI from something like http://localhost:8080/myapp/api to http://localhost:8080/api

Normally I would do this with an annotation such as: @ApplicationPath("api") but that doesnt seem to be applicable, tried the below but doesnt give the desired result.

TestController.java

@Controller
@RequestMapping("api")
public class TestController {
    @RequestMapping("/test")
    public @ResponseBody Test Test() {
        return new Test("Test String");
    }
}

How can this be done with spring?

ServerMonkey
  • 1,042
  • 3
  • 19
  • 42
  • This might be helpful http://stackoverflow.com/questions/2129876/using-spring-mapping-to-root-in-web-xml-static-resources-arent-found – Pankaj Gadge Jan 04 '14 at 04:50
  • 2
    In addition to the other answers/comments here... Generally what you're trying to do isn't really a Spring thing, it's a servlet container (eg. Tomcat, Jetty, JBoss, GlassFish, etc) configuration thing. More commonly, people proxy through Apache to hide the servlet name and port on the running Tomcat (using mod_proxy or mod_rewrite). – reblace Jan 04 '14 at 04:57

1 Answers1

1

Generally configured in META-INF/context.XML. Set path to / or "".

Here's a similar issue with tomcat 7

HOWTO set the context path of a web application in Tomcat 7.0

Community
  • 1
  • 1
Russell Shingleton
  • 3,176
  • 1
  • 21
  • 29