title: How to Set Context root in Spring Mvc Project
body: <p>I am Using Spring MVC project in Tomcat Server.Each time I run the application the server context root is changed.
  How to set fixed context root?</p>
  
  <p>My projectname is: DemoApplication,
  first this context root is deployed the path is,
  <a href="http://localhost:8080/DemoApplication" rel="noreferrer">http://localhost:8080/DemoApplication</a> </p>
  
  <p>second time it is,
  <a href="http://localhost:8080/Controller" rel="noreferrer">http://localhost:8080/Controller</a>
  Web.xml:</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>servlet-context.xml:</p>
  
  <pre><code>&lt;annotation-driven /&gt;
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
      &lt;beans:property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;beans:property name="url"
          value="jdbc:mysql://localhost:3306/mydp" /&gt;
      &lt;beans:property name="username" value="root" /&gt;
      &lt;beans:property name="password" value="root" /&gt;
  &lt;/beans:bean&gt;
  &lt;beans:bean id="hibernate4AnnotatedSessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;beans:property name="dataSource" ref="dataSource" /&gt;
      &lt;beans:property name="annotatedClasses"&gt;
          &lt;beans:list&gt;
               &lt;beans:value&gt;com.Aquatech.Model.Area&lt;/beans:value&gt;
          &lt;/beans:list&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="hibernateProperties"&gt;
          &lt;beans:props&gt;
              &lt;beans:prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect
              &lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.show_sql"&gt;false&lt;/beans:prop&gt;
          &lt;/beans:props&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt; 
  &lt;beans:bean id="GenericDao" class="com.Aquatech.Dao.Impl.GenericDaoImpl"&gt;
   &lt;beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory"&gt;&lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  &lt;beans:bean id="GenericserviceDao" class="com.Aquatech.ServiceDao.Impl.GenericServiceDaoImpl"&gt;
   &lt;beans:property name="genericDao" ref="GenericDao"&gt;&lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  &lt;interceptors&gt;
      &lt;beans:bean id="webContentInterceptor"      class="org.springframework.web.servlet.mvc.WebContentInterceptor"&gt;
          &lt;beans:property name="cacheSeconds" value="0" /&gt;
          &lt;beans:property name="useExpiresHeader" value="true" /&gt;
          &lt;beans:property name="useCacheControlHeader" value="true" /&gt;
          &lt;beans:property name="useCacheControlNoStore" value="true" /&gt;
      &lt;/beans:bean&gt;
  &lt;/interceptors&gt;
  &lt;context:component-scan base-package="com.Aquatech.Controller" /&gt;
  </code></pre>
  
  <p>
  
      
  </p>