Search code examples
springspring-mvcspring-annotations

Set context root for spring annotation based web app


How can set the context root for a annotation based spring web app? Sample application found in following link, https://github.com/bkielczewski/example-spring-mvc-initializer

In browser I can access it as, http://localhost:8080/

I want to change it as, http://localhost:8080/spring

Thanks, Charith


Solution

  • Update your pom.xml to include web-app configuration. See below

    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.0.6.v20130930</version>
        <configuration>
              <webApp>
                  <contextPath>/spring</contextPath>
              </webApp>
              <httpConnector>
                   <port>8080</port>
                   <host>localhost</host>
              </httpConnector>
              <scanIntervalSeconds>10</scanIntervalSeconds>
        </configuration>
    </plugin>