The Shiro Factory interface will resolve to its constructed instance
in Shiro's .ini configuration automatically.

It will not do that in Spring configuration however (Spring has no
knowledge of Shiro's Factory concept and therefore doesn't know how to
automatically resolve the Factory's created instance).

Instead, Spring can support what you want by implementing Spring's
FactoryBean interface.

If your my.package.shiro.EhCacheManagerFactory implementation
implemented FactoryBean (or even better, subclassed
AbstractFactoryBean), I think you will have what you want, but note:

If you're going to do all this in Spring, maybe you should be using
Spring's out-of-the-box EhCacheManagerFactoryBean which already
provides an EhCacheManager in a Spring environment.  I don't know if
it will meet your needs, but it is probably worth checking it out
before you develop your own.

HTH,

--
Les Hazlewood | @lhazlewood
CTO, Stormpath | http://stormpath.com | @goStormpath | 888.391.5282
Stormpath wins GigaOM Structure Launchpad Award! http://bit.ly/MvZkMk


On Thu, Jul 12, 2012 at 7:09 AM, Paweł Piątkowski
<[email protected]> wrote:
> I've got some problems with integrating EhCacheManagerFactory with my Spring
> application.
> As I noticed there is no possibility to use a plain shiro.ini configuration
> file with Spring Framework.
>
> We can only define [Users] and [Roles] sections in ini file and connect it
> in xml configuration in this way:
> */
> <bean name="iniRealm" class="org.apache.shiro.realm.text.IniRealm">
>         <constructor-arg type="java.lang.String" value="classpath:shiro.ini"/>
> </bean>/*
>
> Please let me know if I am wrong.
>
> I was trying to reconstruct my shiro.ini's [Main] section which is:
> *
> /ehCacheManager = my.package.shiro.EhCacheManagerFactory
> cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
> cacheManager.cacheManager = $ehCacheManager
> securityManager.cacheManager = $cacheManager/*
>
> to xml form and I've got:
> *
> /<bean id="ehCacheManager" class="my.package.shiro.EhCacheManagerFactory"/>
>
> <bean id="cacheManager"
> class="org.apache.shiro.cache.ehcache.EhCacheManager">
>         <property name="cacheManager" ref="ehCacheManager"/>
> </bean>
>
> <bean id="securityManager"
> class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
>         <property name="cacheManager" ref="cacheManager"/>
> </bean>/*
>
> Unfortunately I have such error during deployment:
>
> /org.springframework.beans.factory.BeanCreationException: Error creating
> bean with name 'shiroFilter' defined in ServletContext resource
> [/WEB-INF/spring/root-context.xml]: BeanPostProcessor before instantiation
> of bean failed; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name
> 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0'
> defined in ServletContext resource [/WEB-INF/spring/root-context.xml]:
> Cannot resolve reference to bean 'securityManager' while setting bean
> property 'securityManager'; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'securityManager' defined in ServletContext resource
> [/WEB-INF/spring/root-context.xml]: Cannot resolve reference to bean
> 'cacheManager' while setting bean property 'cacheManager'; nested exception
> is org.springframework.beans.factory.BeanCreationException: Error creating
> bean with name 'cacheManager' defined in ServletContext resource
> [/WEB-INF/spring/root-context.xml]: Initialization of bean failed; nested
> exception is org.springframework.beans.ConversionNotSupportedException:
> Failed to convert property value of type
> 'my.package.shiro.shiro.EhCacheManagerFactory' to required type
> 'net.sf.ehcache.CacheManager' for property 'cacheManager'; nested exception
> is java.lang.IllegalStateException: *Cannot convert value of type
> [my.package.shiro.shiro.EhCacheManagerFactory] to required type
> [net.sf.ehcache.CacheManager] for property 'cacheManager': no matching
> editors or conversion strategy found/*
>
> Does anyone knows what should I do now?
>
> -----
> -----------------------
> Paweł Piątkowski
> http://pl.linkedin.com/in/ppiatkowski
> --
> View this message in context: 
> http://shiro-user.582556.n2.nabble.com/Shiro-and-multiple-wars-within-the-same-Servlet-Container-tp5560737p7577596.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Reply via email to