title: No mapping found for HTTP request with URI. Where am I wrong
body: <p>I have these files below. I don't what wrong I am doing. 
  I get an error saying <strong>No mapping found for HTTP request with URI [/pages/j_spring_security_check] in DispatcherServlet with name 'dispatcher'</strong></p>
  
  <p>Can someone please help in this.</p>
  
  <p>ApplicationContext.xml</p>
  
  <pre><code>            &lt;?xml version="1.0" encoding="UTF-8"?&gt;
              &lt;beans xmlns="http://www.springframework.org/schema/beans"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
                  xmlns:webflow-config="http://www.springframework.org/schema/webflow-config"
                  xsi:schemaLocation="http://www.springframework.org/schema/beans 
                     http://www.springframework.org/schema/beans/spring-beans.xsd 
                     http://www.springframework.org/schema/security 
                     http://www.springframework.org/schema/security/spring-security.xsd
                     http://www.springframework.org/schema/webflow-config 
                      http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd"&gt;
  
                  &lt;!-- database properties DataSource --&gt;
                  &lt;!-- &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; 
                      &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" 
                      /&gt; &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" /&gt; &lt;property 
                      name="username" value="system" /&gt; &lt;property name="password" value="123456" 
                      /&gt; &lt;/bean&gt; --&gt;
  
                  &lt;bean id="dataSource"
                      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
                      &lt;property name="driverClassName" value="org.h2.Driver" /&gt;
                      &lt;property name="url"
                          value="jdbc:h2:~/veeratest;DB_CLOSE_ON_EXIT=TRUE;FILE_LOCK=NO" /&gt;
                      &lt;property name="username" value="sa" /&gt;
                      &lt;property name="password" value="12345" /&gt;
                  &lt;/bean&gt;
                  &lt;bean id="sessionFactory"
                      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
  
                      &lt;!-- dependency Injection of dataSource --&gt;
                      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
                      &lt;property name="hibernateProperties"&gt;
                          &lt;props&gt;
                              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
  
                              &lt;!-- hibernate mapping to database automatically --&gt;
                              &lt;!-- when we use create-drop instead of update the table is created automatically 
                                  when the server runs after that it will drop when server stops --&gt;
                              &lt;prop key="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/prop&gt;
  
                              &lt;!-- whether the query wants to show the data in console --&gt;
                              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                              &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
  
                          &lt;/props&gt;
                      &lt;/property&gt;
  
                      &lt;!-- packages to scan for Entity Classes annotated Classes package --&gt;
                      &lt;property name="annotatedClasses"&gt;
                          &lt;list&gt;
                              &lt;value&gt;com.model.Product&lt;/value&gt;
                              &lt;value&gt;com.model.Authorities&lt;/value&gt;
                              &lt;value&gt;com.model.BillingAddress&lt;/value&gt;
                              &lt;value&gt;com.model.Cart&lt;/value&gt;
                              &lt;value&gt;com.model.CartItem&lt;/value&gt;
                              &lt;value&gt;com.model.Customer&lt;/value&gt;
                              &lt;value&gt;com.model.CustomerOrder&lt;/value&gt;
                              &lt;value&gt;com.model.ShippingAddress&lt;/value&gt;
                              &lt;value&gt;com.model.User&lt;/value&gt;
                              &lt;value&gt;com.model.Queries&lt;/value&gt;
                          &lt;/list&gt;
                      &lt;/property&gt;
  
                  &lt;/bean&gt;
  
                  &lt;!-- A transaction manager is the part of an application that is responsible 
                      for coordinating transactions across one or more resources. In the Spring 
                      framework, the transaction manager is effectively the root of the transaction 
                      system. --&gt;
                  &lt;bean id="transactionManager"
                      class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
                      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
                  &lt;/bean&gt;
  
                  &lt;!-- Spring - Security Purpose --&gt;
  
                  &lt;security:http auto-config="true" use-expressions="true"&gt;
                      &lt;security:intercept-url pattern="/index/**"
                          access="permitAll" /&gt;
  
                      &lt;security:intercept-url pattern="/index1/**"
                          access="permitAll" /&gt;
                      &lt;security:intercept-url pattern="/cart/**"
                          access="permitAll" /&gt;
                      &lt;security:intercept-url pattern="/get*/**"
                          access="hasAnyRole('ROLE_ADMIN','ROLE_USER')" /&gt;
                      &lt;security:intercept-url pattern="/admin*/**"
                          access="hasRole('ROLE_ADMIN')" /&gt;
                      &lt;security:intercept-url pattern="/login"
                          access="hasAnyRole('ROLE_ADMIN','ROLE_USER')" /&gt;
                      &lt;!-- &lt;security:form-login login-processing-url="/j_spring_security_check"
                          login-page="/login" authentication-failure-url="/login?error"
                          default-target-url="/index1" username-parameter="j_username"
                          password-parameter="j_password" /&gt;
                      &lt;security:logout logout-success-url="/login?logout" /&gt; --&gt;
  
                  &lt;/security:http&gt;
  
                  &lt;security:authentication-manager&gt;
                      &lt;security:authentication-provider&gt;
                          &lt;security:user-service&gt;
                              &lt;security:user name="rahul@gmail.com" password="12345"
                                  authorities="ROLE_USER" /&gt;
                              &lt;security:user name="admin@gmail.com" password="12345"
                                  authorities="ROLE_ADMIN" /&gt;
                          &lt;/security:user-service&gt;
  
                          &lt;security:jdbc-user-service
                              data-source-ref="dataSource"
                              authorities-by-username-query="SELECT 
                              emailId,authorities FROM authorities WHERE emailId =?"
                              users-by-username-query="SELECT 
                              emailId, password, enabled FROM users WHERE emailId=? " /&gt;
                      &lt;/security:authentication-provider&gt;
  
                  &lt;/security:authentication-manager&gt;
  
                  &lt;webflow-config:flow-executor id="flowExecutor"
                      flow-registry="flowRegistry"&gt;
                  &lt;/webflow-config:flow-executor&gt;
  
                  &lt;webflow-config:flow-registry id="flowRegistry"
                      base-path="/WEB-INF/flow"&gt;
                      &lt;webflow-config:flow-location path="/checkout/checkout-flow.xml"
                          id="checkout"&gt;&lt;/webflow-config:flow-location&gt;
                  &lt;/webflow-config:flow-registry&gt;
                  &lt;bean id="flowHandleMapping"
                      class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"&gt;
                      &lt;property name="flowRegistry" ref="flowRegistry"&gt;&lt;/property&gt;
                  &lt;/bean&gt;
                  &lt;bean id="flowHandlerAdapter"
                      class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"&gt;
                      &lt;property name="flowExecutor" ref="flowExecutor"&gt;&lt;/property&gt;
                  &lt;/bean&gt;
  
              &lt;/beans&gt;
  </code></pre>
  
  <p>dispatcher-servelet.xml
                  </p>
  
  <pre><code>            &lt;beans xmlns="http://www.springframework.org/schema/beans"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
                  xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
                  xsi:schemaLocation="http://www.springframework.org/schema/beans
                     http://www.springframework.org/schema/beans/spring-beans.xsd
                     http://www.springframework.org/schema/mvc
                     http://www.springframework.org/schema/mvc/spring-mvc.xsd
                     http://www.springframework.org/schema/context
                     http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
                  &lt;mvc:annotation-driven&gt;&lt;/mvc:annotation-driven&gt;
  
                  &lt;context:component-scan base-package="com.*"&gt;&lt;/context:component-scan&gt;
  
                  &lt;!-- it will scan all the class under the package com.tutorial create instances 
                      for all the --&gt;
                  &lt;!-- class which has an annotations like @Component, @Controller, @Service, 
                      @Repository --&gt;
  
  
  
                  &lt;!-- Using this it get the actual view name by converting logical view name --&gt;
                  &lt;!-- for eg: logical view name is welcome --&gt;
                  &lt;!-- it will convert it to WEB-INF/Views/welcome.jsp --&gt;
  
                  &lt;bean id="viewResolver"
                      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                      &lt;property name="prefix" value="/WEB-INF/page/" /&gt;
                      &lt;property name="suffix" value=".jsp" /&gt;
                  &lt;/bean&gt;
  
                  &lt;!-- mvc:resources is to find the resource file like bootstrap,css,JQuery 
                      and Images in resource folder --&gt;
  
                  &lt;mvc:resources mapping="/resource/**" location="/WEB-INF/resource/" /&gt;
              &lt;/beans&gt;
  </code></pre>
  
  <p>WebSecurityConfig.Java</p>
  
  <pre><code>            package com.config;
  
              import javax.sql.DataSource;
  
              import org.springframework.beans.factory.annotation.Autowired;
              import org.springframework.context.annotation.Bean;
              import org.springframework.context.annotation.Configuration;
              import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
              import org.springframework.security.config.annotation.web.builders.HttpSecurity;
              import org.springframework.security.config.annotation.web.builders.WebSecurity;
              import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
              import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
              import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
              import org.springframework.security.crypto.password.PasswordEncoder;
              import org.springframework.security.provisioning.JdbcUserDetailsManager;
              import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  
              @EnableWebMvc
              @EnableWebSecurity
              @Configuration
              public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
                  @Autowired
                  DataSource dataSource;
  
                  @Bean
                  public PasswordEncoder passwordEncoder() {
                      return new BCryptPasswordEncoder();
                  }
  
                  // Enable jdbc authentication
                  @Autowired
                  public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
                      auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder());
                  }
  
                  @Bean
                  public JdbcUserDetailsManager jdbcUserDetailsManager() throws Exception {
                      JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager();
                      jdbcUserDetailsManager.setDataSource(dataSource);
                      return jdbcUserDetailsManager;
                  }
  
                  @Override
                  public void configure(WebSecurity web) throws Exception {
                      web.ignoring().antMatchers("/resources/**");
                  }
  
                  @Override
                  protected void configure(HttpSecurity http) throws Exception {
                      http.formLogin().loginProcessingUrl("/j_spring_security_check").and().authorizeRequests()
                              .antMatchers("/register").permitAll().antMatchers("/login").hasAnyRole("USER", "ADMIN")
                              .antMatchers("/login").hasAnyRole("USER", "ADMIN").antMatchers("/addNewEmployee").hasAnyRole("ADMIN")
                              .anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout()
                              .permitAll();
                      /*
                       * http.csrf().disable();
                       */
                  }
              }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>            &lt;?xml version="1.0" encoding="UTF-8"?&gt;
              &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;Veera Enterprises&lt;/display-name&gt;
  
                  &lt;!-- to connect the dispatcher servlet and applicationContext --&gt;
                  &lt;context-param&gt;
                      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
                      &lt;param-value&gt;
                          /WEB-INF/dispatcher-servlet.xml,
                          /WEB-INF/applicationContext.xml
                      &lt;/param-value&gt;
                  &lt;/context-param&gt;
  
              &lt;!--    &lt;filter&gt;
                      &lt;filter-name&gt;
                          springSecurityFilterChain
                      &lt;/filter-name&gt;
                      &lt;filter-class&gt;
                          org.springframework.web.filter.DelegatingFilterProxy
                      &lt;/filter-class&gt;
                  &lt;/filter&gt; --&gt;
  
                  &lt;!-- &lt;filter-mapping&gt; &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt; 
                      &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; --&gt;
                  &lt;filter&gt;
                      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
                      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
                  &lt;/filter&gt;
                  &lt;!-- it is used to listen the contextloader --&gt;
                  &lt;listener&gt;
                      &lt;listener-class&gt;
                          org.springframework.web.context.ContextLoaderListener
                      &lt;/listener-class&gt;
                  &lt;/listener&gt;
  
                  &lt;servlet&gt;
                      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
                      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
                  &lt;/servlet&gt;
  
                  &lt;servlet-mapping&gt;
                      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
                      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
                  &lt;/servlet-mapping&gt;
              &lt;/web-app&gt;
  </code></pre>