带有多个数据源的Spring安全核心的Grails 3.1.8

时间:2016-06-10 13:41:57

标签: tomcat grails grails-plugin

我正面临着使用grails spring-security-core plugin / spring-ldap插件的问题。这是我的第一篇文章link和完整版stacktrace。这是问题所在:

我有一个带有multpile数据源的应用程序和由

添加的spring-security-core插件
`build.gradle ` `compile "org.grails.plugins:spring-security-core:3.1.1"`

在tomcat服务器的build中运行这个应用程序,它工作得很好,但当我尝试在我自己的tomcat中部署war文件时,它失败并出现错误(在链接中),我一直试图找到导致它的原因,首先解决方案是关闭二级缓存,第二个解决方案是从项目中删除spring-security-core插件。我不知道这是一个错误还是我错过了一些配置,可能默认配置还不够? Project正在以前的grails版本3.0.x中工作。如果你想重现错误,只需创建新的grails项目 - 使用web profile,添加多个数据源(oracle,mssql)并尝试在tomcat上部署它。

我认为这可能是插件依赖项的一些问题,因为它也使用了ehcache,并且我依赖hibernate-ehcache,但排除ehcache-core没有帮助。这是包含示例项目的repo link

1 个答案:

答案 0 :(得分:3)

不确定您是否注意到它,但您的堆栈跟踪清楚地表明您已创建重复的CacheManager。您可能需要检查ehcache.xml或ehcache-failsafe.xml

Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the
ame 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 necessa
y
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 org.hibernate.cache.ehcache.EhCacheRegionFactory.start(EhCacheRegionFactory.java:107)
        at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:70)
        at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
        at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
        at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.jav
:91)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251)
        ... 74 common frames omitted
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 necessa
y
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 ]

更新:您可能需要考虑此similar question的配置。基本上他们使用的是共享单例bean,因此可以避免重新创建缓存:

<强> DataSource.groovy中:

cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'

<强> Config.groovy中:

    cacheManager {
        shared = true
    }

我不确定你的情况确实如此(我们没有看到你的配置),但这只是一个开始。