title: Spring + Hibernate + Maven: jCannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql//localhost:3306/test'
body: <p>I have my mysql-connector jar in:</p>
  
  <p>1.) Tomcat Server lib </p>
  
  <p>2.) Build Path as an External JAR.
  * Removed from Maven dependency, although it remains with the same error.</p>
  
  <p><strong>jdbc.properties</strong></p>
  
  <pre><code>jdbc.driverClassName=com.mysql.jdbc.Driver
  jdbc.dialect=org.hibernate.dialect.MySQLDialect
  jdbc.databaseurl=jdbc:mysql//localhost:3306/test
  jdbc.username=root
  jdbc.password=****
  </code></pre>
  
  <p><strong>web.xml</strong> adding it with a snippet:</p>
  
  <pre><code>&lt;resource-ref&gt;
      &lt;description&gt;DB Connection&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/test&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>And my complete <strong>servlet-context.xml</strong></p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="org.springsecudev.controller" /&gt;
  &lt;context:component-scan base-package="org.springsecudev.model" /&gt;
  &lt;context:component-scan base-package="org.springsecudev.service" /&gt;
  &lt;context:component-scan base-package="org.springsecudev.dao" /&gt;
  
  &lt;beans:bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/jdbc.properties"&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
      destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
      p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="sessionFactory" 
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;beans:property name="dataSource" ref="dataSource"/&gt;
      &lt;beans:property name="configLocation"&gt;
          &lt;beans:value&gt;classpath:hibernate.cfg.xml&lt;/beans:value&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="configurationClass"&gt;
          &lt;beans:value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/beans:value&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="hibernateProperties"&gt;
          &lt;beans:props&gt;
              &lt;beans:prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.show_sql"&gt;true&lt;/beans:prop&gt;
          &lt;/beans:props&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;   
  
  &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt;
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
  &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&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="transactionManager" 
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;beans:property name="sessionFactory" ref="sessionFactory"&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;beans:bean id="encoder"  
  class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"&gt;
      &lt;beans:constructor-arg value="12"&gt;&lt;/beans:constructor-arg&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>I also added the <strong>context.xml</strong> in META-INF to be sure I tried this one as well with</p>
  
  <pre><code>&lt;Context&gt;
  &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
  &lt;Resource  name="jdbc/test" 
          username="root" 
          password="root" 
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/test"
          auth="Container" 
          type="javax.sql.DataSource"
          maxActive="100" 
          maxIdle="30" 
          maxWait="10000"
          initialSize="1"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>But still no luck, it also has the same error being:</p>
  
  <blockquote>
    <p>INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@39c45c72: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,propertyConfigurer,dataSource,sessionFactory,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.view.InternalResourceViewResolver#0,transactionManager,org.springframework.web.servlet.handler.MappedInterceptor#0,encoder,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@31e0a986
    WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
    ERROR: org.hibernate.util.JDBCExceptionReporter - Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql//localhost:3306/test'
    WARN : org.hibernate.cfg.SettingsFactory - Could not obtain connection metadata
    java.sql.SQLException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql//localhost:3306/test'
        at org.apache.commons.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2160)....... [ shortened ] <strong>Caused by: java.sql.SQLException: No suitable driver</strong>
        at org.apache.commons.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2151)
        ... 40 more</p>
  </blockquote>
  
  <p>I've been trying to find out what could be the problem wherein I have copied the jar in build path and server lib. </p>