• 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都注册好,看那些博客真是看得心累)

  • 相关阅读:
    ArcGIS for JavaScript继承TiledMapServiceLayer来实现“动态切图”
    Commvault Oracle备份常用命令
    Commvault逻辑架构及组件说明
    数据保护平台如何为新一代应用,人工智能和数据科学提供动力
    SQL Server SSL/TLS 加密
    curl传递大json文件报错解决方法
    MySQL5.5 安装mcafee mysql-audit插件 不成功
    CentOS 6.5安装配置NFS服务器
    利用dump函数理解oracle如何存储各种类型数据
    xfs文件系统挂载大容量磁盘
  • 原文地址:https://www.cnblogs.com/shendaxia1/p/10754973.html
Copyright © 2020-2023  润新知