title: Configure datasource for integrating Spring Security in existing Spring project
body: <p>I am implementing spring security in an existing spring mvc project. I had used xml to configure the spring security. I have used this tutorial for implementing spring security
  <a href="http://www.mkyong.com/spring-security/spring-security-form-login-using-database/" rel="nofollow noreferrer">http://www.mkyong.com/spring-security/spring-security-form-login-using-database/</a></p>
  
  <p>In my project I have a db-source file(<code>MySQL_Datasource.xml</code>) in resources folder just under main (outside of webapp). And the way spring security is implemented in tutorial, the datasource needs to be under webapp folder. I am facing this problem of integration.</p>
  
  <p>Below is the snap of my project structure and on the right side config. code of <code>web.xml</code>, I have commented on the line in image where i have to define my dataSource location.</p>
  
  <p><a href="https://i.stack.imgur.com/TAuEw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TAuEw.png" alt="web.xml"></a></p>
  
  <p>This is code of spring security where dataSource will be used</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.0.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security-3.2.xsd"&gt;
  
      &lt;!-- enable use-expressions --&gt;
      &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;intercept-url pattern="/admin**" access="hasRole('ROLE_ADMIN')" /&gt;
  
          &lt;!-- access denied page --&gt;
          &lt;access-denied-handler error-page="/403" /&gt;
          &lt;form-login 
              login-page="/login" 
              default-target-url="/welcome" 
              authentication-failure-url="/login?error" 
              username-parameter="usr"
              password-parameter="pwd" /&gt;
          &lt;logout logout-success-url="/login?logout"  /&gt;
          &lt;!-- enable csrf protection --&gt;
          &lt;csrf/&gt;
      &lt;/http&gt;
  
      &lt;!-- Select users and user_roles from database --&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 username, role from user_roles where username =?  " /&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>I am doing this first time. I need help so that I can get this done.</p>
  
  <p>UPDATE:</p>
  
  <p>MYSQL_DataSource.xml code:</p>
  
  <pre><code>&lt;bean id="dataSource" class= "org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;      
        &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt;
        &lt;property name="url" value="${jdbc.url}"&gt;&lt;/property&gt;
        &lt;property name="username" value="${jdbc.username}"&gt;&lt;/property&gt;
        &lt;property name="password" value="${jdbc.password}"&gt;&lt;/property&gt;
     &lt;/bean&gt;
  
     &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
       &lt;property name="location"&gt;
          &lt;value&gt;db.properties&lt;/value&gt;
       &lt;/property&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>and below is the db.properties values:</p>
  
  <pre><code>jdbc.url        =   jdbc:mysql://localhost/bhaiyag_prod_grocery
  jdbc.username   =   newuser
  jdbc.password   =   kmsg
  </code></pre>