ssm+shiro错误记录

做了下ssm整合shiro,先记录一下遇到的一个严重的问题

因为之前的习惯我是不在service写接口的(因为懒)所以在写shiro的自定义reamls的时候用shiro去进行一个登陆的验证,所以需要用到自己写的查询方法,所以想的方法是把service自动注入到自定义的reamls中,但是在用@Autowired去进行自动注入的时候会报如下错误

Error creating bean with name 'shiroFilter' defined in class path resource [spring/spring-shiro.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 [spring/spring-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 [spring/spring-shiro.xml]: Cannot resolve reference to bean 'myRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRealm': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wx.service.SysUserService com.wx.security.ShiroSecurityRealm.sysUserService; nested exception is java.lang.IllegalArgumentException: Can not set com.wx.service.SysUserService field com.wx.security.ShiroSecurityRealm.sysUserService to com.sun.proxy.$Proxy17

大概就是springbean初始化都是在springmvc加载后的,而shirofilter是要配置在springmvc之前的,所以在执行shiro、中的自定义reamls类的时候beanfactor中是还没有bean的,所以你把类注入的时候是会报上面的错误的,但是接口是不用在bean中注册的,所以可以注入,所以你要在自定义的reamls中使用自定义方法的时候自动注入的一定要是接口类型.(网上查这些问题的时候,大部分人都是在教怎么在shiro加载的时候将所有bean都注册好,看那些博客真是看得心累)

猜你喜欢

转载自www.cnblogs.com/shendaxia1/p/10754973.html
今日推荐