cas 持久化TGT到mysql JPA方式
cas server版本:6.0.0
添加依赖:
#使用gradle依赖管理
compile group: 'org.apereo.cas', name: 'cas-server-support-jpa-ticket-registry', version: "${project.'cas.version'}"
进行application.properties配置:
##ticket持久化配置 cas.ticket.registry.jpa.user=root cas.ticket.registry.jpa.password=1111 cas.ticket.registry.jpa.driverClass=com.mysql.cj.jdbc.Driver cas.ticket.registry.jpa.url=jdbc:mysql://127.0.0.1:3306/cas?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false cas.ticket.registry.jpa.dialect=org.hibernate.dialect.MySQL8Dialect cas.ticket.registry.jpa.idleTimeout=5000 cas.ticket.registry.jpa.leakThreshold=10 cas.ticket.registry.jpa.autocommit=true
在mysql中的截图如下:
在此过程中遇到的问题一:查看错误日志从关键词查起,此异常不影响运行情况
2019-03-18 19:55:59,010 WARN [com.zaxxer.hikari.pool.ProxyLeakTask] - <Connection leak detection triggered for com.mysql.cj.jdbc.ConnectionImpl@6d963d70 on thread https-jsse-nio-8433-exec-1, stack trace follows> java.lang.Exception: Apparent connection leak detected at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128) ~[HikariCP-3.2.0.jar!/:?] at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.1.Final.jar!/:5.4.1.Final] at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35) ~[hibernate-core-5.4.1.Final.jar!/:5.4.1.Final] at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106) ~[hibernate-core-5.4.1.Final.jar!/:5.4.1.Final] at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136) ~[hibernate-core-5.4.1.Final.jar!/:5.4.1.Final] at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:254) ~[hibernate-core-5.4.1.Final.jar!/:5.4.1.Final] 这个要修改哪个参数? cas server 中对于使用JPA将TGT持久化到mysql: 配置如下: cas.ticket.registry.jpa.user=root cas.ticket.registry.jpa.password=1111 cas.ticket.registry.jpa.driverClass=com.mysql.cj.jdbc.Driver cas.ticket.registry.jpa.url=jdbc:mysql://127.0.0.1:3306/cas?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false cas.ticket.registry.jpa.dialect=org.hibernate.dialect.MySQL8Dialect 此时会出现:Apparent connection leak detected 增加参数: cas.ticket.registry.jpa.idleTimeout=5000 报错消失。
由于我的项目中还是用了redis做验证码缓存,因此一直以为是redis的配置问题,看日志不仔细
com.zaxxer.hikari.pool.ProxyLeakTask释义:
hikari连接池的leakDetectionThreshold,也就是连接池泄露检测。 leakDetectionThreshold 用来设置连接被占用的超时时间,单位为毫秒,默认为0,表示禁用连接泄露检测。 如果大于0且不是单元测试,则进一步判断:(leakDetectionThreshold < SECONDS.toMillis(2) or (leakDetectionThreshold > maxLifetime && maxLifetime > 0),会被重置为0 . 即如果要生效则必须>0,同时满足:不能小于2秒,而且当maxLifetime > 0时不能大于maxLifetime,该值默认为1800000,即30分钟。 作者:go4it 链接:https://juejin.im/post/5a73bb1ff265da4e8f0474a6
问题二:配置参数之后启动出现一下错误日志,但不影响运行【还没有找到修改异常的配置参数】
2019-03-18 19:53:54,606 WARN [org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration] - <Logging config file location 'file:/etc/cas/config/log4j2.xml' cannot be opened and will be ignored> 2019-03-18 19:53:54,676 INFO [org.apereo.cas.web.CasWebApplication] - <The following profiles are active: standalone> 2019-03-18 19:54:05,215 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,226 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings. CAS application context may not have initialized correctly.> 2019-03-18 19:54:05,226 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,298 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,329 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,329 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,330 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,337 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,337 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,338 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,339 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,340 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,340 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,341 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,341 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,342 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,346 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,357 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,357 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings. CAS application context may not have initialized correctly.> 2019-03-18 19:54:05,357 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,361 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,362 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,362 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,362 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,366 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,366 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings. CAS application context may not have initialized correctly.> 2019-03-18 19:54:05,366 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,370 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,371 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,371 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,371 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,372 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,372 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,373 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,374 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,374 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,375 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,375 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,377 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,377 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings. CAS application context may not have initialized correctly.> 2019-03-18 19:54:05,377 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,381 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,394 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,396 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,397 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,397 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,397 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,397 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,398 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,407 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,463 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:05,471 ERROR [org.apereo.cas.jpa.CasHibernatePhysicalNamingStrategy] - <Could not load configuration settings to determine case insensitivity.> 2019-03-18 19:54:18,993 INFO [org.apereo.cas.logging.web.LoggingConfigurationEndpoint] - <Located logging configuration reference in the environment as [file:/etc/cas/config/log4j2.xml]>