SpringBoot 报错:ERROR 10224 --- [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool 已解决

SpringBoot 报错:ERROR 10224 — [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. 解决方案

文章目录

    • eclipse报错
    • 主要问题代码
    • 解决思路
    • 修改为正确代码

eclipse报错

2020-01-30 12:49:04.620 INFO 10224 — [ restartedMain] com.how2java.springboot.Application : Starting Application on LAPTOP-LELBA6ER with PID 10224 (E:\sprbt\springboot_h2j4\target\classes started by int in E:\sprbt\springboot_h2j4)
2020-01-30 12:49:04.620 INFO 10224 — [ restartedMain] com.how2java.springboot.Application : No active profile set, falling back to default profiles: default
2020-01-30 12:49:04.664 INFO 10224 — [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3c63065c: startup date [Thu Jan 30 12:49:04 CST 2020]; root of context hierarchy
2020-01-30 12:49:05.698 INFO 10224 — [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2020-01-30 12:49:05.704 INFO 10224 — [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-30 12:49:05.705 INFO 10224 — [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2020-01-30 12:49:05.852 INFO 10224 — [ost-startStop-1] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2020-01-30 12:49:05.856 INFO 10224 — [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-01-30 12:49:05.856 INFO 10224 — [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1194 ms
2020-01-30 12:49:05.965 INFO 10224 — [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: ‘dispatcherServlet’ to [/]
2020-01-30 12:49:05.968 INFO 10224 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘characterEncodingFilter’ to: [/]
2020-01-30 12:49:05.968 INFO 10224 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘hiddenHttpMethodFilter’ to: [/
]
2020-01-30 12:49:05.968 INFO 10224 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘httpPutFormContentFilter’ to: [/]
2020-01-30 12:49:05.968 INFO 10224 — [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘requestContextFilter’ to: [/
]
2020-01-30 12:49:06.359 ERROR 10224 — [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.

java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1041) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3481) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2445) ~[mysql-connector-java-5.1.21.jar:na]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215) ~[mysql-connector-java-5.1.21.jar:na]

 

主要问题代码

application.properties ↓

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/how2java?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.hbm2ddl.auto=update

pom.xml ↓



    4.0.0
 
  com.how2java
  springboot
  0.0.1-SNAPSHOT
  springboot
  springboot
  war
   
    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.9.RELEASE
    
 
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-tomcat
             
        
        
              junit
              junit
              3.8.1
              test
        
        
        
              javax.servlet
              javax.servlet-api
               
        
              
                     javax.servlet
                     jstl
              
        
        
               org.apache.tomcat.embed
               tomcat-embed-jasper
                
            
        
            org.springframework.boot
            spring-boot-devtools
            true 
        
         
        
        
            mysql
            mysql-connector-java
            5.1.21
        
 
        
        
            org.springframework.boot
            spring-boot-starter-data-jpa
               
    
 
    
        1.8
    
 
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    
 

 

解决思路

注意到报错代码中的加粗字体:
ConnectionPool : Unable to create initial connections of pool. //不能初始化连接池连接;
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long // sql中BigInteger 不能强制转换位Long,可能存在sql兼容问题

  1. 我们可以把问题定位到mysql的配置或者版本上的问题;检查application.properties 中mysql连接配置没有问题。
  2. 检查pom.xml 中mysql jar版本为5.1.21。而本地服务器mysql版本为8.0.18。修改pom.xml的mysql jar包版本为本地mysql版本8.0.18。
  3. mysql8.0以上版本datasource.url需加上serverTimezone属性;

 

修改为正确代码

pom.xml ↓

        <!-- mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>

application.properties ↓

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/how2java?characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.hbm2ddl.auto=update

修改以上代码后,springboot应用再jdk8环境下正常打开。

你可能感兴趣的:(SpringBoot 报错:ERROR 10224 --- [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool 已解决)