作为一名Sping初学者,今天第一次配置Spring数据源就遇到好几个坑人的地方,记录下来做个备忘。
1.
Mon Nov 27 21:42:01 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Mon Nov 27 21:42:02 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Mon Nov 27 21:42:02 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Mon Nov 27 21:42:02 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
向数据库发送请求后一直都在报这个,其实这个问题早在学习jdbc时就遇到了,只需要在jdbc的URL后面加上 useUnicode=true&characterEncoding=utf-8&useSSL=false 即可;
2.
Loading class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver‘. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
原来的jdbc驱动是 com.mysql.jdbc.Driver , 改为 com.mysql.cj.jdbc.Driver 即可;
3.
1 27-Nov-2017 21:58:49.667 警告 [C3P0PooledConnectionPoolManager[identityToken->1hgefi99r1yeux661are7zk|12876430]-HelperThread-#0] com.mchange.v2.resourcepool.BasicResourcePool. com[email protected]74bb9e1f -- 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 (10). Last acquisition attempt exception: 2 java.sql.SQLException: The server time zone value ‘???ú±ê×??±??‘ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. 3 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121) 4 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) 5 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:81) 6 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:55) 7 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:65) 8 at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:70) 9 at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:853) 10 at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:440) 11 at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) 12 at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221) 13 at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) 14 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) 15 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) 16 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203) 17 at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138) 18 at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125) 19 at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44) 20 at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870) 21 at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696) 22 Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value ‘???ú±ê×??±??‘ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. 23 at sun.reflect.GeneratedConstructorAccessor15.newInstance(Unknown Source) 24 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 25 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 26 at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54) 27 at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) 28 at com.mysql.cj.core.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:118) 29 at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:360) 30 at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1434) 31 at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:986) 32 at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:843) 33 ... 12 more 34 35 27-Nov-2017 21:58:49.669 严重 [C3P0PooledConnectionPoolManager[identityToken->1hgefi99r1yeux661are7zk|12876430]-HelperThread-#0] com.mchange.v2.resourcepool.BasicResourcePool. A RESOURCE POOL IS PERMANENTLY BROKEN! [com[email protected]74bb9e1f] (because a series of 10 acquisition attempts failed.) 36 27-Nov-2017 21:58:49.671 严重 [C3P0PooledConnectionPoolManager[identityToken->1hgefi99r1yeux661are7zk|12876430]-HelperThread-#0] com.mchange.v2.resourcepool.BasicResourcePool. [email protected] -- Unexpectedly broken!!! 37 com.mchange.v2.resourcepool.ResourcePoolException: Unexpected Break Stack Trace! 38 at com.mchange.v2.resourcepool.BasicResourcePool.unexpectedBreak(BasicResourcePool.java:974) 39 at com.mchange.v2.resourcepool.BasicResourcePool.access$1000(BasicResourcePool.java:44) 40 at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1927) 41 at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696) 42 43 27-Nov-2017 21:58:49.678 信息 [http-nio-8080-exec-4] com.mchange.v2.resourcepool.BasicResourcePool. [email protected] -- an attempt to checkout a resource was interrupted, because the pool is now closed. [Thread: http-nio-8080-exec-4]
关键在第二行,在jdbc的url后面在加上一个 serverTimezone=UTC 就行了。
最后上一下最终修改好的数据源配置代码
jdbc.properties
1 ###### C3P0 MySQL CONFIG ####### 2 jdbc.driverClassName=com.mysql.cj.jdbc.Driver 3 jdbc.url=jdbc:mysql://localhost/localstudent?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC 4 jdbc.username=root 5 jdbc.password=123456 6 7 connection.initialPoolSize=1 8 connection.minPoolSize=1 9 connection.maxPoolSize=5 10 connection.acquireIncrement=2 11 connection.acquireRetryAttempts=10 12 connection.acquireRetryDelay=1000 13 connection.maxIdleTime=3600 14 connection.idleConnectionTestPeriod=20 15 connection.maxStatements=0 16 connection.maxStatementsPerConnection=0
springmvc-servlet.xml
1 <!-- 获取mysql数据库连接池配置信息 --> 2 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 3 <property name="locations" value="classpath:config/jdbc.properties"/> 4 </bean> 5 <!-- 配置c3p0数据源连接池 --> 6 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 7 destroy-method="close"> 8 <property name="driverClass" value="${jdbc.driverClassName}"/> 9 <property name="jdbcUrl" value="${jdbc.url}"/> 10 <property name="user" value="${jdbc.username}"/> 11 <property name="password" value="${jdbc.password}"/> 12 <property name="initialPoolSize" value="${connection.initialPoolSize}"/> 13 <property name="minPoolSize" value="${connection.minPoolSize}"/> 14 <property name="maxPoolSize" value="${connection.maxPoolSize}"/> 15 <property name="acquireIncrement" value="${connection.acquireIncrement}"/> 16 <property name="acquireRetryAttempts" value="${connection.acquireRetryAttempts}"/> 17 <property name="acquireRetryDelay" value="${connection.acquireRetryDelay}"/> 18 <property name="maxIdleTime" value="${connection.maxIdleTime}"/> 19 <property name="idleConnectionTestPeriod" value="${connection.idleConnectionTestPeriod}"/> 20 <property name="maxStatements" value="${connection.maxStatements}"/> 21 <property name="maxStatementsPerConnection" value="${connection.maxStatementsPerConnection}"/> 22 <property name="preferredTestQuery" value="select 1"/> 23 <property name="breakAfterAcquireFailure" value="true"/> 24 <property name="testConnectionOnCheckout" value="false"/> 25 </bean>
时间: 2024-11-09 00:21:32