title: Using MySql database with Spring security in login form
body: <p>I am developing a login form using Spring MVC . I used Spring security for the login , the login and the password are sotred in a MySql data base along with the " ROLE_USER " . I imported all the necessary libraries (spring security , spring JDBC , mysql connector java , ....) But when I Run the app on the server many exceptions are raised . </p>
  
  <pre><code>SEVERE: Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.security.provisioning.JdbcUserDetailsManager] for bean with name 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
  Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.security.provisioning.JdbcUserDetailsManager] for bean with name 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.security.provisioning.JdbcUserDetailsManager] for bean with name 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1269)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:581)
      at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1335)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:356)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:322)
      at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1174)
      at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:75)
      at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.java:58)
      at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
      at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
      at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
      at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
      at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:399)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
      ... 21 more
  Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
      at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
      at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
      at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at org.springframework.util.ClassUtils.forName(ClassUtils.java:260)
      at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1287)
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1258)
      ... 37 more
  </code></pre>
  
  <p>here is my files : </p>
  
  <p>spring-database.xml </p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
  
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/mydb" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Spring-security.xml </p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
  
  http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  
  
  http://www.springframework.org/schema/security
  
  
  http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  &lt;http auto-config="true"&gt;
          &lt;intercept-url pattern="/basics*" access="ROLE_USER" /&gt;
          &lt;form-login login-page="/login" default-target-url="/basics"
              authentication-failure-url="/loginfailed" /&gt;
          &lt;logout logout-success-url="/logout" /&gt;
      &lt;/http&gt;
   &lt;authentication-manager&gt; 
          &lt;authentication-provider&gt; 
              &lt;jdbc-user-service data-source-ref="dataSource"
  
                  users-by-username-query="
                      select username,password, enabled 
                      from users where USERNAME=?" 
  
                  authorities-by-username-query="
                      select u.username, ur.authority from users u, user_roles ur 
                      where u.user_id = ur.user_id and u.username =?  " 
  
              /&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>What is the solution to my Problem ? Thank You :)</p>