在配置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实在比较麻烦,而且会造成很多的重复代码!
笔记,完