You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by whitneyrzoller <wh...@gmail.com> on 2012/06/21 15:15:12 UTC

EhCache initialization exception: Another unnamed CacheManager already exists in the same VM

Hello all, 

I am trying to get EhCache configured to handle authorization caching.
Currently I am getting the following exception:
org.apache.shiro.cache.CacheException: 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.

My shiro.ini looks like:
[main]
...
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
securityManager.cacheManager = $cacheManager

>From this StackOverflow post it looks like people using Spring have gotten
around this issue by forcing the CacheManager to be a singleton
(http://stackoverflow.com/questions/10013288/another-unnamed-cachemanager-already-exists-in-the-same-vm-ehcache-2-5)

Is anybody aware of work-arounds not using Spring initialization? Is there
some manner of enforcing singleton configuration from the shiro.ini?

Thank you in advance

--
View this message in context: http://shiro-user.582556.n2.nabble.com/EhCache-initialization-exception-Another-unnamed-CacheManager-already-exists-in-the-same-VM-tp7577532.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: EhCache initialization exception: Another unnamed CacheManager already exists in the same VM

Posted by Jared Bunting <ja...@peachjean.com>.
This sounds concerning.  It sounds like your shiro context is getting 
instantiated more than once.  I think that this is worth looking into 
before you look into workarounds for your cache.  Or are you using the 
ehcache.xml in more than one place?

On Thu 21 Jun 2012 09:00:46 AM CDT, whitneyrzoller wrote:
> Thanks Jared for your quick reply, it seems that naming the root element in
> the ehcache.xml doesn't avoid the core problem (same-ish exception:
> org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException:
> Another CacheManager with same name 'shiro' already exists in the same
> VM...)
>
> ...so I think I'll take your second suggestion and just implement my own
> factory class that will enforce a singleton instantiation.
>
> Thank you again.
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/EhCache-initialization-exception-Another-unnamed-CacheManager-already-exists-in-the-same-VM-tp7577532p7577534.html
> Sent from the Shiro User mailing list archive at Nabble.com.



Re: EhCache initialization exception: Another unnamed CacheManager already exists in the same VM

Posted by whitneyrzoller <wh...@gmail.com>.
Thanks Jared for your quick reply, it seems that naming the root element in
the ehcache.xml doesn't avoid the core problem (same-ish exception:
org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException:
Another CacheManager with same name 'shiro' already exists in the same
VM...)

...so I think I'll take your second suggestion and just implement my own
factory class that will enforce a singleton instantiation.

Thank you again.

--
View this message in context: http://shiro-user.582556.n2.nabble.com/EhCache-initialization-exception-Another-unnamed-CacheManager-already-exists-in-the-same-VM-tp7577532p7577534.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: EhCache initialization exception: Another unnamed CacheManager already exists in the same VM

Posted by Jared Bunting <ja...@peachjean.com>.
In your ehcache.xml file, does adding a name attribute to the root 
element help?

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
    name="shiro">

Something like that?

On the other hand, if you really want a singleton, you can write a 
EhCacheManagerFactory that implements org.apache.shiro.util.Factory.  
You'd configure it something like this:

ehCacheManager=com.mycompany.MyEhCacheManagerFactory
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManager=ehCacheManager
securityManager.cacheManager = $cacheManager

-Jared

On Thu 21 Jun 2012 08:15:12 AM CDT, whitneyrzoller wrote:
> Hello all,
>
> I am trying to get EhCache configured to handle authorization caching.
> Currently I am getting the following exception:
> org.apache.shiro.cache.CacheException: 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.
>
> My shiro.ini looks like:
> [main]
> ...
> cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
> cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
> securityManager.cacheManager = $cacheManager
>
> From this StackOverflow post it looks like people using Spring have gotten
> around this issue by forcing the CacheManager to be a singleton
> (http://stackoverflow.com/questions/10013288/another-unnamed-cachemanager-already-exists-in-the-same-vm-ehcache-2-5)
>
> Is anybody aware of work-arounds not using Spring initialization? Is there
> some manner of enforcing singleton configuration from the shiro.ini?
>
> Thank you in advance
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/EhCache-initialization-exception-Another-unnamed-CacheManager-already-exists-in-the-same-VM-tp7577532.html
> Sent from the Shiro User mailing list archive at Nabble.com.