Wow, I have no idea why this would occur - @Autowired clearly works
for your ApplicationContext injection, but not another bean?  That
doesn't make any sense to me at all.

I have an @Autowired Realm implementation in my Spring app and its
@Autowired dependencies are injected just fine.  I'm not sure why
you're seeing this.

Les

On Wed, Mar 13, 2013 at 9:13 PM, NabbleReallySucks
<[email protected]> wrote:
> This had cost me a few days last week, but I had a custom Realm where I would
> @Autowired in a Service class that I need to query data with. Yes a Service
> that was calling down to a Repository. I even tried to @Autowired the
> Repository. Now the Repository is a Spring Data JPA Repository. I inject
> this Service and Repository in many other classes and @Autowired works fine.
> It injects it as needed.
>
> However, it doesn't in the custom Realm. I get the typical exception from
> Spring saying it couldn't find a candidate for autowiring. However, there is
> a BeanDefinition for the Repository and Service in the ApplicationContext,
> so those beans to inject are being created. And the Realm is also defined as
> a Spring <bean>
>
> <bean id="blahRealm"
> class="com.blah.account.security.shiro.realm.BlahRealm">
>         <property name="credentialsMatcher" ref="hashMatcher"/>
>     </bean>
>
> But it didn't work. So I have to do a hack and @Autowired the
> ApplicationContext into the Realm and then getBean() to get it into the
> Realm like the following code.
>
>
>
> public class BlahRealm extends AuthorizingRealm {
>
>   @Autowired
>   ApplicationContext context;
>
>   private AccountService accountService;
>
>   @PostConstruct
>   public void why() {
>     System.out.println("In Post");
>   }
>
>   private AccountService getAccountService() {
>     if (this.accountService == null) {
>       this.accountService = context.getBean(AccountService.class);
>     }
>     return this.accountService;
>   }
>
> So, my question is why doesn't @Autowired work. I assume it is a timing
> thing.
>
> Thanks
>
> Mark
>
>
>
> --
> View this message in context: 
> http://shiro-user.582556.n2.nabble.com/Autowired-just-doesn-t-ever-seem-to-work-in-my-Shiro-implementations-tp7578384.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Reply via email to