title: Spring Data REST example that doesn't use root for mapping
body: <p>I cannot figure out where to modify the Spring Data REST service so that it is NOT in root /</p>
  
  <p>I'm looking over the JavaDoc for RepositoryRestMvcConfiguration , but if anyone has an idea I'd appreciate some guidance.</p>
  
  <p><strong>My webConfiguration.java</strong></p>
  
  <pre><code>@Configuration
  public class WebConfiguration extends RepositoryRestMvcConfiguration {
  
  }
  </code></pre>
  
  <p>If I can I'd like to write a how-to on getting this working, but not finding anyone else using non root.. ie http:// server /servicename/entity?foo=bar</p>
  
  <p>Tried modifying servlet initializer too, but nothing.</p>
  
  <p><strong>My webAppInitializer.java</strong></p>
  
  <pre><code>import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  
  public class WebAppInitializer extends
          AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class&lt;?&gt;[] { AppConfiguration.class };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[] { WebConfiguration.class };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { "/servicename" }; 
      }
  
  }
  </code></pre>
  
  <p>Result from attempting to hit the service </p>
  
  <pre><code>Welcome to the REST shell. For assistance hit TAB or type "help".
  http://server:8080:&gt; discover
  http://server:8080/servicename Command failed
  org.springframework.web.client.HttpClientErrorException: 404 Not Found
  http://server:8080/servicename:&gt; 
  </code></pre>
  
  <p><strong>EDIT: Tomcat failed to deploy my Spring Data Rest servlet</strong>
  hence the service isn't responding.</p>
  
  <p>Now trying to figure out why this occurred :</p>
  
  <pre><code>13:16:55.806 [localhost-startStop-1] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'appConfiguration'
  
  13:16:55.814 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class whichdegree.webmvc.AppConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean whichdegree.webmvc.AppConfiguration.entityManagerFactory()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class whichdegree.webmvc.AppConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource whichdegree.webmvc.AppConfiguration.dataSource()] threw exception; nested exception is java.lang.IllegalStateException: Driver for test database type [HSQL] is not available in the classpath
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.0.M3.jar:4.0.0.M3]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.0.M3.jar:4.0.0.M3]
  &gt;...
  </code></pre>
  
  <p><strong>EDIT 2 : added hsqldb.jar to classpath. Service now running but servlet.init still threw an  exception</strong></p>
  
  <p>I'm going to do some more research on HSQL, and see if I can't solve this exception myself.  Will mark the relevant answer regarding mapping as correct and open a new question for this exception below if I need to.</p>
  
  <pre><code> exception
  
  javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:722)
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryExporterHandlerAdapter' defined in class whichdegree.webmvc.WebConfiguration: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.rest.webmvc.ResourceProcessorInvokingHandlerAdapter.getReturnValueHandlers()Lorg/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite;
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1507)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:299)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:295)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:665)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:512)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:160)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:722)
  root cause
  
  java.lang.NoSuchMethodError: org.springframework.data.rest.webmvc.ResourceProcessorInvokingHandlerAdapter.getReturnValueHandlers()Lorg/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite;
      org.springframework.data.rest.webmvc.ResourceProcessorInvokingHandlerAdapter.afterPropertiesSet(ResourceProcessorInvokingHandlerAdapter.java:83)
      org.springframework.data.rest.webmvc.RepositoryRestHandlerAdapter.afterPropertiesSet(RepositoryRestHandlerAdapter.java:26)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1566)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1503)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:299)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:295)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:665)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:512)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:160)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:722)
  </code></pre>