android 循环引用,spring循环引用

在配置shiro的时候出了这么个问题:

org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'shiroFilter' defined in class path resource [shiro/applicationContext-shiro.xml]:

BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#5':

Cannot resolve reference to bean 'druid-stat-pointcut' while setting bean property 'pointcut';

nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'druid-stat-pointcut' defined in class path resource [applicationContext.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 class path resource

[shiro/applicationContext-shiro.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 class path resource [shiro/applicationContext-shiro.xml]: Cannot resolve reference to bean 'userRealm' while setting bean property 'realm';

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealm': I

njection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:

Error creating bean with name 'usersServiceImpl': Bean with name 'usersServiceImpl' has been injected into other beans

[wxEchoMpMessageRouter,wxEchoMpMessageHandler,dutyDaoImpl,fileManageServiceImpl] in its raw version as part of a circular reference, but has eventually

been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider

using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

大致的意思是,在userRealm中注入了usersService,而在userService中注入了dutyService等几个service,但是同时在这几个service中也注入了usersService,所以产生了循环注入的问题。但是这个问题在没有配置userRealm之前是没有出现过的。以上报错在最后给出了改正的提示,依据提示找到了一篇博客:

解决的办法大致是定义一个webapplicationcontext对象继承自Xmlwebapplicationcontext,将其中的AllowRawInjectionDespiteWrapping设置为true。

public class MyWebApplicationContext extends XmlWebApplicationContext {

@Override

protected DefaultListableBeanFactory createBeanFactory() {

DefaultListableBeanFactory beanFactory =  super.createBeanFactory();

beanFactory.setAllowRawInjectionDespiteWrapping(true);

return beanFactory;

}

}

web.xml中添加:

contextClass

xxx.MyWebApplicationContext

问题解决,对博主的感激之情无以言表啊!

但是,这里有几个问题:

为什么在没有配置userRealm之前没有暴露这个循环引用的问题。

对于这个问题最正确的解决办法是将相关的Service解耦,但是,对于像dutyService和dutyService这样的相互调用我觉得是比较正常的,如果直接调用底层的Dao实在比较麻烦,而且会造成很多的重复代码!

笔记,完

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值