shiro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Turner (Commented) (JIRA)" <>
Subject [jira] [Commented] (SHIRO-352) Shiro annotations with @Component and getBean(Type)
Date Tue, 27 Mar 2012 13:46:27 GMT


Bryan Turner commented on SHIRO-352:

So, based on what I see in your Spring context, you've got a pretty default configuration,
which means the proxy is targeting interfaces. That means that if you try to retrieve the
{{Processor}} implementation using {{InfoProcessor}}, you'll be able to get it when the annotation
_is not_ present, because the bean itself is available directly in the Spring context, but
you won't be able to when the annotation _is_ present because the underlying {{InfoProcessor}}
bean is not available. This is an intentional part of Spring; when a bean is being proxied
for AOP, it should not be possible to get an instance of that bean to which the AOP advisors
are not applied.

I'm assuming you're going to have multiple {{Processor}} implementations each bound to different
{{Command}} types. That would mean you can't retrieve the bean by interface. You have a a
couple of options. One would be to map to bean names, rather than {{Processor}} classes. Another
is to change the Spring configuration so that proxies target classes.

To do the latter, first ensure you've got cglib in your classpath. Then try adding configuration
like this to your Spring context:
<aop:config proxy-target-class="true"/>

That may fix it. You can find more information at

Hope this helps!
> Shiro annotations with @Component and getBean(Type)
> ---------------------------------------------------
>                 Key: SHIRO-352
>                 URL:
>             Project: Shiro
>          Issue Type: Bug
>          Components: Integration: Spring
>    Affects Versions: 1.2.0
>         Environment: Linux, Spring, Java
>            Reporter: Matt Friedman
> I have a bean where I'd like to annotate one of the methods with the @RequiresAuthentication
> When using the @RequiresAuthentication annotation and calling applicationContext.getBean(Class<?>)
spring does not find my bean. Commenting out @RequiresAuthentication allows spring to find
the bean. 
> Using the string name of the bean instead of the type (i.e. applicationContext.getBean(String))
does work. 
> // this causes spring to be unable to find the bean when using @RequiresAuthentication

> Class<? extends Processor> processorType = command.getProcessorType();
> Processor processor = applicationContext.getBean(processorType);
> // However this works:
> Processor processor = applicationContext.getBean(processorStringName);

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message