Bear in mind that I haven't done this myself. But the issue resolves
around the fact that EhCache only allows one CacheManager per name
statically, and Shiro doesn't use EhCache's "create or retrieve"
method. I personally don't care for the EhCache pattern here - in my
mind passing in a config file and potentially getting back a
CacheManager that is completely unrelated except that it shares the
same name is a fair bit counterintuitive to me. Seems to open up the
doors to confusing and misleading problems down the road.
However, if you want to share a single CacheManager between multiple
webapps you need to instructor Shiro to use EhCache's create or
retrieve method.
The factory should look something like this:
package com.example.shiro;
import net.sf.ehcache.CacheManager;
import org.apache.shiro.util.Factory;
public class SharedEhCacheManagerFactory implements
Factory<CacheManager>
{
private String configFile;
@Override
public CacheManager getInstance()
{
return CacheManager.newInstance(this.configFile);
}
public String getConfigFile()
{
return configFile;
}
public void setConfigFile(final String configFile)
{
this.configFile = configFile;
}
}
And then your shiro.ini would look something like this:
ehCacheManager = com.example.shiro.SharedEhCacheManagerFactory
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManager=$ehCacheManager
Hope that helps,
Jared
On Fri 29 Jun 2012 07:17:18 AM CDT, PPiatkowski wrote:
> Jared, could you please give me a little hint how to achieve this "one line
> method"?
>
> You've told that factory class should implement
> org.apache.shiro.util.Factory interface. It gives us T getInstance()
> method
> to implement in our class.
>
> I think that getInstance() method should return EhCacheManager object but
> how can I create instance or return from some context for example by given
> Ehcache name?
>
> Pawel
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Shiro-and-multiple-wars-within-the-same-Servlet-Container-tp5560737p7577562.html
> Sent from the Shiro User mailing list archive at Nabble.com.