title: Cannot resolve No WebApplicationContext found: no ContextLoaderListener registered
body: <p>I'm trying to create Spring web application with annotations only(no configuration xml files). I am using tomcat as application server and maven for build the project. Googled a lot, modified a lot but still stuck with this error. Please find below the files. Hope some one can help me. Thanks in advance. :)</p>
  
  <p><strong>Below is the pom.xml</strong></p>
  
  <pre><code>   &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.mycompany.app&lt;/groupId&gt;
      &lt;artifactId&gt;Angular&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.1&lt;/version&gt;
      &lt;name&gt;Angular Maven Webapp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
              &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
              &lt;version&gt;3.2.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;3.2.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-hibernate3&lt;/artifactId&gt;
              &lt;version&gt;2.0.8&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
                      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
                      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-commons-core&lt;/artifactId&gt;
              &lt;version&gt;1.4.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.2.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
              &lt;artifactId&gt;sqljdbc4&lt;/artifactId&gt;
              &lt;version&gt;4.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;3.6.10.Final&lt;/version&gt;
              &lt;optional&gt;true&lt;/optional&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;asm&lt;/artifactId&gt;
                      &lt;groupId&gt;asm&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;3.2.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-dao&lt;/artifactId&gt;
              &lt;version&gt;2.0.8&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;3.2.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;finalName&gt;Angular&lt;/finalName&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>the initializer file</strong></p>
  
  <pre><code>package com.sample.main;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRegistration;
  
  import org.springframework.web.WebApplicationInitializer;
  import org.springframework.web.context.ContextLoaderListener;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  import com.sample.configuration.Configurations;
  import com.sample.configuration.MvcConfigurations;
  
  public class WebAppInitializer implements WebApplicationInitializer {
  
      public void onStartup(ServletContext servletContext)
              throws ServletException {
          // TODO Auto-generated method stub
          AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
          rootContext.register(Configurations.class);
          rootContext.refresh();
  
          servletContext.addListener(new ContextLoaderListener(rootContext));
          servletContext.setInitParameter("defaultHtmlEscape", "true");
  
          AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
          mvcContext.register(MvcConfigurations.class);
          mvcContext.refresh();
  
          ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
                  "dispatcher", new DispatcherServlet(mvcContext));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/test/*");
  
      }
  
  }
  </code></pre>
  
  <p><strong>The MVC configuration files</strong></p>
  
  <pre><code>package com.sample.configuration;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
  
  
  @Configuration
  @EnableWebMvc
  @ComponentScan(basePackages={"com.sample.controller"})
  public class MvcConfigurations {
  
      @Bean
      public InternalResourceViewResolver viewResolver(){
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setPrefix("/req/");
          resolver.setSuffix(".jsp");
          return resolver;
      }
  
  
  }
  </code></pre>
  
  <p>** The root configuration **    </p>
  
  <pre><code>package com.sample.configuration;
  
  import java.util.Properties;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  
  import org.apache.commons.dbcp.BasicDataSource;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.orm.hibernate4.HibernateExceptionTranslator;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.Database;
  import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories("com.sample.repo")
  @ComponentScan("com.sample")
  public class Configurations {
  
      @Bean
      public DataSource dataSource(){
          BasicDataSource basicDataSource = new BasicDataSource();
          basicDataSource.setUrl("jdbc:sqlserver://127.0.0.1:1433;databaseName=Garuda");
          basicDataSource.setUsername("sa");
          basicDataSource.setPassword("garuda123");
          basicDataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          basicDataSource.setMaxActive(5);
          basicDataSource.setMinIdle(3);
          return basicDataSource;
      }
  
      /*@Bean
      public PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor(){
          PersistenceExceptionTranslationPostProcessor processor = new  PersistenceExceptionTranslationPostProcessor();
          return processor;
      }*/
  
      @Bean
      public HibernateExceptionTranslator hibernateExceptionTranslator(){
          HibernateExceptionTranslator exceptionTranslator = new HibernateExceptionTranslator();
          return exceptionTranslator;
      }
  
      @Bean
      public EntityManagerFactory entityManagerFactory(){
          LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
          bean.setDataSource(dataSource());
          bean.setPackagesToScan("com.sample.domain");
          HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
          jpaVendorAdapter.setDatabase(Database.SQL_SERVER);
          //jpaVendorAdapter.setGenerateDdl(true);
          //jpaVendorAdapter.setShowSql(true);
          bean.setJpaDialect(new HibernateJpaDialect());
          bean.setJpaProperties(hibernateProperties());
          bean.setJpaVendorAdapter(jpaVendorAdapter);
          bean.afterPropertiesSet();
          return bean.getObject();
      }
  
      @Bean
      public JpaTransactionManager transactionManager(){
          JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
          jpaTransactionManager.setEntityManagerFactory(entityManagerFactory());
          return jpaTransactionManager;
      }
  
      public Properties hibernateProperties(){
          Properties properties = new Properties();
          properties.put("hibernate.hbm2ddl.auto", "update");
          properties.put("hibernate.show_sql", "true");
          properties.put("hibernate.format_sql", "true");`enter code here`
          return  properties;
      }
  }
  </code></pre>
  
  <p><strong>The controller file</strong></p>
  
  <pre><code>package com.sample.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.sample.domain.Aircraft;
  import com.sample.repo.AircraftRepo;
  import com.sample.repo.MaintenanceCheckRepo;
  import com.sample.vo.AircraftVO;
  
  @Controller
  public class MvcController {
  
      @Autowired
      AircraftRepo aircraftRepo;
  
      @Autowired
      MaintenanceCheckRepo maintenanceCheckRepo;
  
      @RequestMapping("/addAircraft")
      public ModelAndView addAircraft(@ModelAttribute AircraftVO aircraftVO) {
          ModelAndView view = new ModelAndView();
          Aircraft aircraft = aircraftRepo.saveAndFlush(convertVOToEntity(aircraftVO));
          view.getModelMap().addAttribute("aircraftVO", convertEntityToVO(aircraft));
          view.setViewName("index");
          return view;
      }
  
  
      public Aircraft convertVOToEntity(AircraftVO aircraftVO){
          Aircraft aircraft = new Aircraft();
          aircraft.setAircraftRegistration(aircraftVO.getAircraftRegistration());
          aircraft.setAircraftSubType(null);
          return aircraft;
      }
  
      public AircraftVO convertEntityToVO(Aircraft aircraft){
          AircraftVO aircraftVO = new AircraftVO();
          aircraftVO.setAircraftRegistration(aircraft.getAircraftRegistration());
          aircraftVO.setAircraftSubtypeVO(null);
          aircraftVO.setId(aircraft.getId());
          return aircraftVO;
      }
  }
  </code></pre>
  
  <p><strong>The repository</strong></p>
  
  <pre><code>package com.sample.repo;
  
  
  import org.springframework.data.jpa.repository.JpaRepository;
  
  import com.sample.domain.Aircraft;
  
  public interface AircraftRepo extends JpaRepository&lt;Aircraft,Long&gt;{
  
  
  }
  </code></pre>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>&lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;html&gt;
  &lt;body&gt;
      &lt;h2&gt;Hello World!&lt;/h2&gt;
      &lt;form:form method="post" action="test/addAircraft"
          commandName="aircraftVO"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Aircraft Reg No:&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="aircraftRegistration" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;input type="submit" value="Add Aircraft" /&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Web.xml</strong></p>
  
  <pre><code>&lt;!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;
  
  &lt;web-app&gt;
      &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Adding stackTrace:</strong></p>
  
  <pre><code>SEVERE: Servlet.service() for servlet [jsp] in context with path [/Angular] threw exception [An exception occurred processing JSP page /index.jsp at line 5
  
  2: &lt;html&gt;
  3: &lt;body&gt;
  4:  &lt;h2&gt;Hello World!&lt;/h2&gt;
  5:  &lt;form:form method="post" action="test/addAircraft"
  6:      commandName="aircraftVO"&gt;
  7:      &lt;table&gt;
  8:          &lt;tr&gt;
  
  Stacktrace:] with root cause
  java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
  at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
  at org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:85)
  at org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:209)
  at org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:74)
  at org.springframework.web.servlet.support.JspAwareRequestContext.&lt;init&gt;(JspAwareRequestContext.java:48)
  at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
  at org.apache.jsp.index_jsp._jspx_meth_form_005fform_005f0(index_jsp.java:98)
  at org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:363)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:306)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:203)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>