CAS5.2配置mysql连接 Could not create connection to database server. Attempted reconnect 3 times.

问题介绍

作者根据网上的众多教程用cas5.2.x配置mysql验证时,均失败,经谷歌未找到相似问题。多次重装环境未得到解决。终于发现是jdbc的url参数问题。

环境

tomcat 9.0.16
cas-overlay-template-5.2
mysql 5.6.14

报错信息

2019-03-31 22:59:03,543 ERROR [org.apereo.cas.authentication.PolicyBasedAuthenticationManager] - <Authentication has failed. Credentials may be incorrect or CAS cannot find authentication handler that supports [zhaosi] of type [UsernamePasswordCredential]. Examine the configuration to ensure a method of authentication is defined and analyze CAS logs at DEBUG level to trace the authentication event.>
2019-03-31 22:59:03,545 INFO [org.apereo.inspektr.audit.support.Slf4jLoggingAuditTrailManager] - =============================================================
WHO: zhaosi
WHAT: Supplied credentials: [zhaosi]
ACTION: AUTHENTICATION_FAILED
APPLICATION: CAS
WHEN: Sun Mar 31 22:59:03 CST 2019
CLIENT IP ADDRESS: 127.0.0.1
SERVER IP ADDRESS: 127.0.0.1
=============================================================

java.sql.SQLNonTransientConnectionException: Could not create connection to database server.

解决方案

笔者使用以下url能成功连接:

mysql://127.0.0.1:3306/cas?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false

具体是cas文件夹中配置文件application.properties内的一行配置:

cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/cas?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false

一些疑惑

常见的cas5配置教程中如下配置application.properties文件:

cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/cas_sso_record?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false

cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/yellowcong?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false

但笔者始终无法成功连接。猜想是需要配置serverTimezone参数?但网上教程提到配置该参数的均是mysql6及以上版本,笔者为mysql 5.6.14。

你可能感兴趣的:(CAS5.2配置mysql连接 Could not create connection to database server. Attempted reconnect 3 times.)