从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"
}
然后,带有aclCacheManager的springAclService的问题出现在 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和here的讨论来看,似乎较新的版本(即grails 2.5.0中使用的版本)不允许多个未命名的缓存管理器,因此,一旦在Windows Server 2003上创建了spring-security-acl插件,它将无法创建自己的管理器。 Hibernate CacheManager已创建。
我本以为命名休眠的CacheManager可以解决此问题(就像您已经做过的一样),但是没有骰子。
我的临时(未试用)解决方法是将以下内容添加到应用程序的resources.groovy中:
aclCacheManager(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) {
shared = true
}
我实际上不知道这是否意味着ACL插件现在将与Hibernate共享相同的缓存管理器,但是我现在对缓存不感到困惑,因此只要我的应用程序正在运行,我就很高兴。
试试看,看看你如何过。