title: Tomcat v 9.0 - Public Key Retrieval is not allowed
body: <p>I am building web application using Spring and Hibernate. I am using Tomcat version 9.0 and mysql-connector-java-8.0.12.jar</p>
  
  <p>I am trying to run my program using Tomcat, I am getting this error.</p>
  
  <p>Any help would be appreciated. I tried all the solutions but none worked for me.</p>
  
  <pre><code>May 12, 2019 6:01:22 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@37045b48 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@46e75b5c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
  java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@37045b48 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@158da6c2 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
  java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  
  May 12, 2019 6:02:54 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 0, SQLState: null
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@37045b48 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  May 12, 2019 6:02:54 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: Connections could not be acquired from the underlying database!
  May 12, 2019 6:02:54 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/web-customer-tracker] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection] with root cause
  java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@701a20b -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
  java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@47b1f8e4 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
  java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@37045b48 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@37045b48 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@48ada644 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
  java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  
  May 12, 2019 6:02:54 PM com.mchange.v2.resourcepool.BasicResourcePool 
  WARNING: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@37045b48 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  
  
  </code></pre>
  
  <p>This is my database connection manager file</p>
  
  <pre><code>package com.luv2code.testdb;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.sql.*;
  /**
   * Servlet implementation class TestDbServlet
   */
  @WebServlet("/TestDbServlet")
  public class TestDbServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      // setup connection variables
      String user = "springstudent";
      String pass = "springstudent";
  
      String jdbcUrl = "jdbc:mysql://localhost:3306/web_customer_tracker?allowPublicKeyRetrieval=true&amp;useSSL=false&amp;serverTimezone=UTC";
      String driver = "com.mysql.cj.jdbc.Driver";
      // get connection to the database
      try {
          PrintWriter out = response.getWriter();
  
          out.println("Connecting to Database: " + jdbcUrl);
  
          Class.forName(driver);
  
          Connection myConn = DriverManager.getConnection(jdbcUrl, user, pass);
  
          out.println("SUCCESS!!");
          myConn.close();
      }
      catch (Exception exc) {
          exc.printStackTrace();
          throw new ServletException(exc);
      }
  
      }
  
  }
  
  </code></pre>
  
  <p>This is my spring-mvc.xml file</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:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;!-- Add support for component scanning --&gt;
      &lt;context:component-scan base-package="com.luv2code.springdemo" /&gt;
  
      &lt;!-- Add support for conversion, formatting and validation support --&gt;
      &lt;mvc:annotation-driven/&gt;
  
      &lt;!-- Define Spring MVC view resolver --&gt;
      &lt;bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/view/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Step 1: Define Database DataSource / connection pool --&gt;
      &lt;bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close"&gt;
          &lt;property name="driverClass" value="com.mysql.cj.jdbc.Driver" /&gt;
          &lt;property name="jdbcUrl" value="jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&amp;amp;serverTimezone=UTC" /&gt;
          &lt;property name="user" value="springstudent" /&gt;
          &lt;property name="password" value="springstudent" /&gt; 
  
          &lt;!-- these are connection pool properties for C3P0 --&gt;
          &lt;property name="minPoolSize" value="5" /&gt;
          &lt;property name="maxPoolSize" value="20" /&gt;
          &lt;property name="maxIdleTime" value="30000" /&gt;
      &lt;/bean&gt;  
  
      &lt;!-- Step 2: Setup Hibernate session factory --&gt;
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="myDataSource" /&gt;
          &lt;property name="packagesToScan" value="com.luv2code.springdemo.entity" /&gt;
          &lt;property name="hibernateProperties"&gt;
             &lt;props&gt;
                &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
             &lt;/props&gt;
          &lt;/property&gt;
     &lt;/bean&gt;    
  
      &lt;!-- Step 3: Setup Hibernate transaction manager --&gt;
      &lt;bean id="myTransactionManager"
              class="org.springframework.orm.hibernate5.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Step 4: Enable configuration of transactional behavior based on annotations --&gt;
      &lt;tx:annotation-driven transaction-manager="myTransactionManager" /&gt;
  
      &lt;mvc:resources location="/resources/" mapping="/resources/**" &gt;&lt;/mvc:resources&gt;
  &lt;/beans&gt;
  
  
  
  
  
  
  </code></pre>