zoukankan      html  css  js  c++  java
  • 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都注册好,看那些博客真是看得心累)

  • 相关阅读:
    Java Web(5) Spring 下使用Junit4 单元测试
    聊聊单元测试(三)——Spring Test+JUnit完美组合
    浅谈ELK日志分析平台
    ELK 实现 Java 分布式系统日志分析架构
    ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台
    开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)入门学习资源索引
    自动补全下拉框(可输入匹配的下拉框)
    这是一篇满载真诚的微信小程序开发干货
    微服务化的多组件项目,跨地域、分布式版本管理和发布方式
    解放双手,发掘更大的价值:智能化运维
  • 原文地址:https://www.cnblogs.com/shendaxia1/p/10754973.html
Copyright © 2011-2022 走看看