NutzCN Logo
问答 NutzBoot 如何集成ehcache 实现session持久化
发布于 1666天前 作者 Hamming 1339 次浏览 复制 上一个帖子 下一个帖子
标签:

NutzBoot 如何集成ehcache 实现session持久化
项目配置

shiro.realm.cache.enable =true
shiro.session.cache.type=ehcache

那如何指定ehcache.xml的路径呢
如何查看ehcache是否生效

15 回复

呃 只看到 j2cache demo

日志打印 显示 缓存是memory

|79  |shiro.realm.cache.enable                |no        |                    |          |realm是否缓存           |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|80  |shiro.session.cache.redis.debug         |no        |                    |false     |session持久化时redis的debug模式|org.nutz.boot.starter.shiro.ShiroEnvStarter|
|81  |shiro.session.cache.redis.mode          |no        |                    |kv        |设置redis缓存的模式        |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|82  |shiro.session.cache.redis.ttl           |no        |                    |-1        |redis缓存的过期时间        |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|83  |shiro.session.cache.type                |no        |                    |memory    |设置使用的缓存类型           |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|84  |shiro.session.cookie.httpOnly           |no        |                    |true      |Cookie是否只读          |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|85  |shiro.session.cookie.maxAge             |no        |                    |946080000 |Cookie的过期时间,单位:毫秒   |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|86  |shiro.session.cookie.name               |no        |                    |sid       |Cookie的name         |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|87  |shiro.session.dao.iocName               |no        |                    |shiroSessionDao|SessionDao的ioc名称,设置并声明该IocBean,就能覆盖默认的SessionDao实现|org.nutz.boot.starter.shiro.ShiroEnvStarter|
|88  |shiro.session.enable                    |no        |                    |true      |是否启用Shiro的Session管理 |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|89  |shiro.session.manager.globalSessionTimeout|no        |                    |1800000   |全局session过期时间       |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|90  |shiro.session.manager.sessionValidationInterval|no        |                    |3600000   |定期检查session过期的周期    |org.nutz.boot.starter.shiro.ShiroEnvStarter|
|91  |shiro.session.manager.sessionValidationSchedulerEnabled|no        |                    |true      |是否定期检查session过期     |org.nutz.boot.starter.shiro.ShiroEnvStarter|

那是手册,与配置值无关,不会打印当前配置的值

看样子 似乎是集成成功了

[DEBUG] 14:13:11.943 org.nutz.boot.starter.shiro.ShiroEnvStarter.getCacheManager(ShiroEnvStarter.java:207) - using session cache = ehcache
[DEBUG] 14:13:11.943 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'shiroEhcacheCacheManager'<interface org.apache.shiro.cache.CacheManager>
[DEBUG] 14:13:11.944 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:192) - 	 >> Load definition name=shiroEhcacheCacheManager
[DEBUG] 14:13:11.944 org.nutz.ioc.loader.combo.ComboIocLoader.printFoundIocBean(ComboIocLoader.java:226) - Found IocObject(shiroEhcacheCacheManager) in AnnotationIocLoader(packages=[org.nutz.boot.starter])
[DEBUG] 14:13:11.944 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:223) - 	 >> Make...'shiroEhcacheCacheManager'<interface org.apache.shiro.cache.CacheManager>
[DEBUG] 14:13:11.944 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:65) - Save object 'shiroEhcacheCacheManager' to [app] 
[DEBUG] 14:13:11.944 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'shiroEnvStarter'<>
[DEBUG] 14:13:11.956 net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:132) - Configuring ehcache from ehcache.xml found in the classpath: file:/Users/apple/IdeaProjects/EasyToRent/target/classes/ehcache.xml
[DEBUG] 14:13:11.956 net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:98) - Configuring ehcache from URL: file:/Users/apple/IdeaProjects/EasyToRent/target/classes/ehcache.xml
[DEBUG] 14:13:11.957 net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:150) - Configuring ehcache from InputStream
[DEBUG] 14:13:11.968 net.sf.ehcache.config.BeanHandler.setAttribute(BeanHandler.java:271) - Ignoring ehcache attribute xmlns:xsi
[DEBUG] 14:13:11.969 net.sf.ehcache.config.BeanHandler.setAttribute(BeanHandler.java:271) - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
[DEBUG] 14:13:11.971 net.sf.ehcache.config.DiskStoreConfiguration.translatePath(DiskStoreConfiguration.java:141) - Disk Store Path: /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T/
[WARN ] 14:13:11.980 net.sf.ehcache.config.CacheConfiguration.setStatistics(CacheConfiguration.java:2388) - Statistics can no longer be enabled via configuration.
[DEBUG] 14:13:11.981 net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1102) - Creating new CacheManager with default config
[DEBUG] 14:13:11.984 net.sf.ehcache.util.PropertyUtil.parseProperties(PropertyUtil.java:87) - propertiesString is null.
[DEBUG] 14:13:11.992 net.sf.ehcache.config.ConfigurationHelper.createCacheManagerEventListener(ConfigurationHelper.java:189) - No CacheManagerEventListenerFactory class specified. Skipping...
[DEBUG] 14:13:17.036 net.sf.ehcache.Cache.createBootstrapCacheLoader(Cache.java:1044) - No BootstrapCacheLoaderFactory class specified. Skipping...
[DEBUG] 14:13:17.036 net.sf.ehcache.Cache.createCacheWriter(Cache.java:1017) - CacheWriter factory not configured. Skipping...
[DEBUG] 14:13:17.036 net.sf.ehcache.config.ConfigurationHelper.createCacheExceptionHandler(ConfigurationHelper.java:100) - No CacheExceptionHandlerFactory class specified. Skipping...
[DEBUG] 14:13:17.041 net.sf.ehcache.Cache.createBootstrapCacheLoader(Cache.java:1044) - No BootstrapCacheLoaderFactory class specified. Skipping...
[DEBUG] 14:13:17.041 net.sf.ehcache.Cache.createCacheWriter(Cache.java:1017) - CacheWriter factory not configured. Skipping...
[DEBUG] 14:13:17.041 net.sf.ehcache.config.ConfigurationHelper.createCacheExceptionHandler(ConfigurationHelper.java:100) - No CacheExceptionHandlerFactory class specified. Skipping...
[DEBUG] 14:13:17.058 net.sf.ehcache.DiskStorePathManager.resolveAndLockIfNeeded(DiskStorePathManager.java:169) - Using diskstore path /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T
[DEBUG] 14:13:17.058 net.sf.ehcache.DiskStorePathManager.resolveAndLockIfNeeded(DiskStorePathManager.java:170) - Holding exclusive lock on /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T/.ehcache-diskstore.lock
[DEBUG] 14:13:17.062 net.sf.ehcache.store.disk.DiskStorageFactory.<init>(DiskStorageFactory.java:170) - Matching data file missing (or empty) for index file. Deleting index file /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T/shiro-session%0043ache.index
[DEBUG] 14:13:17.063 net.sf.ehcache.store.disk.DiskStorageFactory.deleteFile(DiskStorageFactory.java:838) - Failed to delete file shiro-session%0043ache.index
[DEBUG] 14:13:17.097 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE
[DEBUG] 14:13:17.098 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES
[DEBUG] 14:13:17.099 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: WRITER_QUEUE_LENGTH
[DEBUG] 14:13:17.099 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: REMOTE_SIZE
[DEBUG] 14:13:17.099 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LAST_REJOIN_TIMESTAMP
[DEBUG] 14:13:17.109 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_GET
[DEBUG] 14:13:17.110 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_PUT
[DEBUG] 14:13:17.111 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_REMOVE
[DEBUG] 14:13:17.111 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_COMMIT
[DEBUG] 14:13:17.112 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_ROLLBACK
[DEBUG] 14:13:17.112 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_RECOVERY
[DEBUG] 14:13:17.112 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: CLUSTER_EVENT
[DEBUG] 14:13:17.113 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: NONSTOP
[DEBUG] 14:13:17.116 net.sf.ehcache.Cache.initialise(Cache.java:1262) - Initialised cache: shiro-sessionCache
[DEBUG] 14:13:17.117 net.sf.ehcache.config.ConfigurationHelper.createCacheDecorators(ConfigurationHelper.java:334) - CacheDecoratorFactory not configured. Skipping for 'shiro-sessionCache'.
[DEBUG] 14:13:17.117 net.sf.ehcache.config.ConfigurationHelper.createDefaultCacheDecorators(ConfigurationHelper.java:364) - CacheDecoratorFactory not configured for defaultCache. Skipping for 'shiro-sessionCache'.
[DEBUG] 14:13:17.121 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'shiroRealm'<class org.apache.shiro.realm.AuthorizingRealm>
[DEBUG] 14:13:17.965 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:234) - No authorizationCache instance set.  Checking for a cacheManager...
[DEBUG] 14:13:17.965 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:242) - CacheManager [org.apache.shiro.cache.ehcache.EhCacheManager@7f13811b] has been configured.  Building authorization cache named [io.nutz.nutzsite.common.shiro.SimpleAuthorizingRealm.authorizationCache]
[INFO ] 14:13:17.965 org.apache.shiro.cache.ehcache.EhCacheManager.getCache(EhCacheManager.java:159) - Cache with name 'io.nutz.nutzsite.common.shiro.SimpleAuthorizingRealm.authorizationCache' does not yet exist.  Creating now.
[DEBUG] 14:13:17.976 net.sf.ehcache.store.MemoryStore.<init>(MemoryStore.java:180) - Initialized net.sf.ehcache.store.MemoryStore for io.nutz.nutzsite.common.shiro.SimpleAuthorizingRealm.authorizationCache
[DEBUG] 14:13:17.978 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE
[DEBUG] 14:13:17.978 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES
[DEBUG] 14:13:17.978 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_DISK_SIZE
[DEBUG] 14:13:17.978 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_DISK_SIZE_BYTES
[DEBUG] 14:13:17.979 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: WRITER_QUEUE_LENGTH
[DEBUG] 14:13:17.979 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: REMOTE_SIZE
[DEBUG] 14:13:17.979 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LAST_REJOIN_TIMESTAMP
[DEBUG] 14:13:17.981 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_GET
[DEBUG] 14:13:17.981 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_PUT
[DEBUG] 14:13:17.981 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_REMOVE
[DEBUG] 14:13:17.981 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: DISK_GET
[DEBUG] 14:13:17.981 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: DISK_PUT
[DEBUG] 14:13:17.982 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: DISK_REMOVE
[DEBUG] 14:13:17.982 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_COMMIT
[DEBUG] 14:13:17.982 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_ROLLBACK
[DEBUG] 14:13:17.982 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_RECOVERY
[DEBUG] 14:13:17.983 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: CLUSTER_EVENT
[DEBUG] 14:13:17.983 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: NONSTOP
[DEBUG] 14:13:17.984 net.sf.ehcache.Cache.initialise(Cache.java:1262) - Initialised cache: io.nutz.nutzsite.common.shiro.SimpleAuthorizingRealm.authorizationCache
[DEBUG] 14:13:17.984 net.sf.ehcache.config.ConfigurationHelper.createDefaultCacheDecorators(ConfigurationHelper.java:364) - CacheDecoratorFactory not configured for defaultCache. Skipping for 'io.nutz.nutzsite.common.shiro.SimpleAuthorizingRealm.authorizationCache'.
[INFO ] 14:13:17.984 org.apache.shiro.cache.ehcache.EhCacheManager.getCache(EhCacheManager.java:166) - Added EhCache named [io.nutz.nutzsite.common.shiro.SimpleAuthorizingRealm.authorizationCache]
[DEBUG] 14:13:17.985 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'shiroRememberMeManager'<interface org.apache.shiro.mgt.RememberMeManager>
[DEBUG] 14:13:17.985 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:192) - 	 >> Load definition name=shiroRememberMeManager

ehcache配置如下
那么 我需要在哪里再设置 缓存 shrio 用的是 shiro-sessionCache呢

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
    monitoring="autodetect" dynamicConfig="true" name="nutzsite">
    <diskStore path="java.io.tmpdir"/>
    <cache name="shiro-sessionCache"
           maxElementsInMemory="1000"
           overflowToDisk="true"
           eternal="true"
           timeToLiveSeconds="0"
           timeToIdleSeconds="0"
           diskPersistent="true"
           diskExpiryThreadIntervalSeconds="600"/>

    <defaultCache maxElementsInMemory="10000" eternal="false"
                  timeToIdleSeconds="86400" timeToLiveSeconds="86400" overflowToDisk="false"
                  diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
                  statistics="false" />
</ehcache>

配置文件 指定 这样指定 有用吗

# cacheManager
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
##shiro
#shiro.session.dao.iocName=onlineSessionDAO
shiro.realm.cache.enable=true
shiro.session.cache.type=ehcache
# Session
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
sessionManager.sessionValidationSchedulerEnabled = false

# Session Cache
sessionDAO=org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
sessionDAO.cacheManager=$cacheManager
sessionDAO.activeSessionsCacheName=shiro-sessionCache
sessionManager.sessionDAO=$sessionDAO
securityManager.sessionManager=$sessionManager

似乎 配置 没有生效

[DEBUG] 14:50:37.493 net.sf.ehcache.util.PropertyUtil.parseProperties(PropertyUtil.java:87) - propertiesString is null.
[DEBUG] 14:50:37.501 net.sf.ehcache.config.ConfigurationHelper.createCacheManagerEventListener(ConfigurationHelper.java:189) - No CacheManagerEventListenerFactory class specified. Skipping...
[DEBUG] 14:50:42.543 net.sf.ehcache.Cache.createBootstrapCacheLoader(Cache.java:1044) - No BootstrapCacheLoaderFactory class specified. Skipping...
[DEBUG] 14:50:42.544 net.sf.ehcache.Cache.createCacheWriter(Cache.java:1017) - CacheWriter factory not configured. Skipping...
[DEBUG] 14:50:42.544 net.sf.ehcache.config.ConfigurationHelper.createCacheExceptionHandler(ConfigurationHelper.java:100) - No CacheExceptionHandlerFactory class specified. Skipping...
[DEBUG] 14:50:42.549 net.sf.ehcache.Cache.createBootstrapCacheLoader(Cache.java:1044) - No BootstrapCacheLoaderFactory class specified. Skipping...
[DEBUG] 14:50:42.549 net.sf.ehcache.Cache.createCacheWriter(Cache.java:1017) - CacheWriter factory not configured. Skipping...
[DEBUG] 14:50:42.549 net.sf.ehcache.config.ConfigurationHelper.createCacheExceptionHandler(ConfigurationHelper.java:100) - No CacheExceptionHandlerFactory class specified. Skipping...
[DEBUG] 14:50:42.566 net.sf.ehcache.DiskStorePathManager.resolveAndLockIfNeeded(DiskStorePathManager.java:169) - Using diskstore path /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T
[DEBUG] 14:50:42.566 net.sf.ehcache.DiskStorePathManager.resolveAndLockIfNeeded(DiskStorePathManager.java:170) - Holding exclusive lock on /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T/.ehcache-diskstore.lock
[DEBUG] 14:50:42.570 net.sf.ehcache.store.disk.DiskStorageFactory.<init>(DiskStorageFactory.java:170) - Matching data file missing (or empty) for index file. Deleting index file /var/folders/pk/j26kgdcn53q7f0jdj8c_hlh40000gn/T/shiro-session%0043ache.index
[DEBUG] 14:50:42.570 net.sf.ehcache.store.disk.DiskStorageFactory.deleteFile(DiskStorageFactory.java:838) - Failed to delete file shiro-session%0043ache.index
[DEBUG] 14:50:42.604 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE
[DEBUG] 14:50:42.605 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES
[DEBUG] 14:50:42.605 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: WRITER_QUEUE_LENGTH
[DEBUG] 14:50:42.606 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: REMOTE_SIZE
[DEBUG] 14:50:42.606 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) - Mocking Pass-Through Statistic: LAST_REJOIN_TIMESTAMP
[DEBUG] 14:50:42.615 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_GET
[DEBUG] 14:50:42.615 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_PUT
[DEBUG] 14:50:42.616 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: OFFHEAP_REMOVE
[DEBUG] 14:50:42.617 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_COMMIT
[DEBUG] 14:50:42.617 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_ROLLBACK
[DEBUG] 14:50:42.617 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: XA_RECOVERY
[DEBUG] 14:50:42.618 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: CLUSTER_EVENT
[DEBUG] 14:50:42.618 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) - Mocking Operation Statistic: NONSTOP
[DEBUG] 14:50:42.622 net.sf.ehcache.Cache.initialise(Cache.java:1262) - Initialised cache: shiro-sessionCache
[DEBUG] 14:50:42.622 net.sf.ehcache.config.ConfigurationHelper.createCacheDecorators(ConfigurationHelper.java:334) - CacheDecoratorFactory not configured. Skipping for 'shiro-sessionCache'.
[DEBUG] 14:50:42.622 net.sf.ehcache.config.ConfigurationHelper.createDefaultCacheDecorators(ConfigurationHelper.java:364) - CacheDecoratorFactory not configured for defaultCache. Skipping for 'shiro-sessionCache'.

用默认路径就好啦

这些配置如何指定呢 sessionDAO.activeSessionsCacheName=shiro-sessionCache
不需要指定?

# cacheManager
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile = classpath:ehcache.xml

# Session
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
sessionManager.sessionValidationSchedulerEnabled = false

# Session Cache
sessionDAO=org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
sessionDAO.cacheManager=$cacheManager
sessionDAO.activeSessionsCacheName=shiro-sessionCache
sessionManager.sessionDAO=$sessionDAO
securityManager.sessionManager=$sessionManager

用了shiro.ini的话,application.properties里面的大部分shiro配置都无效了

这些默认名称就不要改动啦

spring shiro 缓存是如下配置

    <!-- Let's use some enterprise caching support for better performance.  You can replace this with any enterprise
         caching framework implementation that you like (Terracotta+Ehcache, Coherence, GigaSpaces, etc -->
    <!--  
    2. 配置 CacheManager. 
    2.1 需要加入 ehcache 的 jar 包及配置文件. 
    -->     
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <!-- Set a net.sf.ehcache.CacheManager instance here if you already have one.  If not, a new one
             will be creaed with a default config:
             <property name="cacheManager" ref="ehCacheManager"/> -->
        <!-- If you don't have a pre-built net.sf.ehcache.CacheManager instance to inject, but you want
             a specific Ehcache configuration to be used, specify that here.  If you don't, a default
             will be used.: -->
        <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/> 
    </bean>
    
    <bean id="authenticator" 
    	class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
    	<property name="authenticationStrategy">
    		<bean class="org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy"></bean>
    	</property>
    </bean>

那么 nutzboot 如何设置呢 classpath:ehcache.xml 路径呢

自定义一个ioc bean, 名字叫 "ehcacheCacheManager", 参考org.nutz.boot.starter.shiro.ShiroEnvStarter.getShiroEhcacheCacheManager()

加个配置项?

呃 创建了 这个类 这样写行么
不用配置 ehcache.xml 路径吗

package io.nutz.nutzsite.common.shiro.cache;

import net.sf.ehcache.CacheManager;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 *
 * @Author: Haimming
 * @Date: 2019-10-09 16:23
 * @Version 1.0
 */
@IocBean(name = "ehcacheCacheManager")
public class EhcacheCacheManager {

    private CacheManager cacheManager;

    public EhcacheCacheManager() {
        CacheManager cacheManager = CacheManager.getInstance();
        if (cacheManager != null) {
            this.cacheManager =  cacheManager;
        }
        this.cacheManager = CacheManager.newInstance();
    }
}

CacheManager.newInstance()

这里可以自定义路径的

添加回复
请先登陆
回到顶部