Grails 2.5 和 SpringAcl:无法访问 aclCacheManager bean
Grails 2.5 & SpringAcl: aclCacheManager bean not accessible
从 2.4.x 迁移到最新的 2.5.0 版本后,我在数据源中更改了一些休眠参数:
cache.region.factory_class =
'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
和Config.groovy:
grails.cache.enabled = true
grails.cache.clearAtStartup = true
grails.hibernate.cache.queries = false
beans.cacheManager.cacheManagerName = 'springcacheCacheManager'
beans.cacheManager.shared = true
在resources.groovy中,ehcache bean是这样设置的:
ehcache(EhCacheFactoryBean) { bean ->
cacheManager = ref("springcacheCacheManager")
cacheName = "cache"
eternal = false
shared = true
diskPersistent = false
memoryStoreEvictionPolicy = "LRU"
maxEntriesLocalHeap = "10000"
timeToIdleSeconds = "120"
timeToLiveSeconds = "120"
maxEntriesLocalDisk = "10000000"
diskExpiryThreadIntervalSeconds = "120"
}
然后,springAclService with aclCacheManager 的问题出现在bootstrap:
objc[41029]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. |Loading Grails
2.5.0 |Configuring classpath . |Environment set to development ................................. |Packaging Grails application ........... |Compiling 1 source files .................................................................Log4j consoleLevel: WARN appFile Level: DEBUG .. |Running Grails application objc[41057]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. Log4j consoleLevel: WARN appFile Level: DEBUG Configuring Spring Security Core ... ... finished configuring Spring Security Core Configuring Spring Security ACL ... ... finished configuring Spring Security ACL 2015-03-28 18:53:44,111 ERROR [DefaultUrlMappingEvaluator$UrlMappingBuilder] - URL mapping argument [exception] with value [(*)] must be a valid class 2015-03-28 18:53:44,113 ERROR [DefaultUrlMappingEvaluator$UrlMappingBuilder] - URL mapping argument [exception] with value [(*)] must be a valid class 2015-03-28 18:53:45,342 ERROR [GrailsContextLoaderListener] - Error initializing the application: Error creating bean with name 'afterAclCollectionRead': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'afterAclCollectionRead': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:529) at net.sf.ehcache.CacheManager.init(CacheManager.java:374) at net.sf.ehcache.CacheManager.<init>(CacheManager.java:259) ... 4 more Error |
我刚刚在尝试从 grails 2.4.3 -> 2.5.0 升级时遇到了同样的问题。
我认为问题源于新 Hibernate/Cache 插件创建 CacheManager 的方式发生了变化。从讨论 here, here and here 看来,较新的版本(即 grails 2.5.0 中使用的版本)不允许使用多个未命名的缓存管理器,因此 spring-security-acl 插件将无法创建其创建 Hibernate CacheManager 后拥有自己的管理器。
我原以为命名 hibernate CacheManager 会解决这个问题(就像你已经做的那样),但没有成功。
我的临时(未经测试)解决方法是将以下内容添加到我的应用程序的 resources.groovy:
aclCacheManager(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) {
shared = true
}
我实际上不知道这是否意味着 ACL 插件现在将与 Hibernate 共享相同的缓存管理器,但我现在对缓存不太在意,所以我很高兴只要我的应用程序是运行.
试一试,看看效果如何。
从 2.4.x 迁移到最新的 2.5.0 版本后,我在数据源中更改了一些休眠参数:
cache.region.factory_class =
'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
和Config.groovy:
grails.cache.enabled = true
grails.cache.clearAtStartup = true
grails.hibernate.cache.queries = false
beans.cacheManager.cacheManagerName = 'springcacheCacheManager'
beans.cacheManager.shared = true
在resources.groovy中,ehcache bean是这样设置的:
ehcache(EhCacheFactoryBean) { bean ->
cacheManager = ref("springcacheCacheManager")
cacheName = "cache"
eternal = false
shared = true
diskPersistent = false
memoryStoreEvictionPolicy = "LRU"
maxEntriesLocalHeap = "10000"
timeToIdleSeconds = "120"
timeToLiveSeconds = "120"
maxEntriesLocalDisk = "10000000"
diskExpiryThreadIntervalSeconds = "120"
}
然后,springAclService with aclCacheManager 的问题出现在bootstrap:
objc[41029]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. |Loading Grails
2.5.0 |Configuring classpath . |Environment set to development ................................. |Packaging Grails application ........... |Compiling 1 source files .................................................................Log4j consoleLevel: WARN appFile Level: DEBUG .. |Running Grails application objc[41057]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. Log4j consoleLevel: WARN appFile Level: DEBUG Configuring Spring Security Core ... ... finished configuring Spring Security Core Configuring Spring Security ACL ... ... finished configuring Spring Security ACL 2015-03-28 18:53:44,111 ERROR [DefaultUrlMappingEvaluator$UrlMappingBuilder] - URL mapping argument [exception] with value [(*)] must be a valid class 2015-03-28 18:53:44,113 ERROR [DefaultUrlMappingEvaluator$UrlMappingBuilder] - URL mapping argument [exception] with value [(*)] must be a valid class 2015-03-28 18:53:45,342 ERROR [GrailsContextLoaderListener] - Error initializing the application: Error creating bean with name 'afterAclCollectionRead': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'afterAclCollectionRead': Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityAclAclService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache': Cannot resolve reference to bean 'ehcacheAclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheAclCache': Cannot resolve reference to bean 'aclCacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCacheManager': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] ... 4 more Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ] at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:529) at net.sf.ehcache.CacheManager.init(CacheManager.java:374) at net.sf.ehcache.CacheManager.<init>(CacheManager.java:259) ... 4 more Error |
我刚刚在尝试从 grails 2.4.3 -> 2.5.0 升级时遇到了同样的问题。
我认为问题源于新 Hibernate/Cache 插件创建 CacheManager 的方式发生了变化。从讨论 here, here and here 看来,较新的版本(即 grails 2.5.0 中使用的版本)不允许使用多个未命名的缓存管理器,因此 spring-security-acl 插件将无法创建其创建 Hibernate CacheManager 后拥有自己的管理器。
我原以为命名 hibernate CacheManager 会解决这个问题(就像你已经做的那样),但没有成功。
我的临时(未经测试)解决方法是将以下内容添加到我的应用程序的 resources.groovy:
aclCacheManager(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) {
shared = true
}
我实际上不知道这是否意味着 ACL 插件现在将与 Hibernate 共享相同的缓存管理器,但我现在对缓存不太在意,所以我很高兴只要我的应用程序是运行.
试一试,看看效果如何。