zoukankan      html  css  js  c++  java
  • 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法

    先来看问题

    这里写图片描述 
    这里写图片描述 
    这里写图片描述

    纠结了几个小时终于找到了问题所在,因为shiro的realm属于Filter,简单说就是初始化realm时,spring还未加载相关业务Bean,那么解决办法就是将springmvc的配置文件加载提前。

    解决办法 
    打开web.xml文件

    这里写图片描述 
    这里写图片描述

    OK,问题解决!

    解决方式2(不建议)

    public TenantServiceTypeTask(ServletContextEvent event) {
            super();
            ServletContext sc=event.getServletContext();
            ApplicationContext beans = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
            userService = (TenantIdentityService) beans.getBean("userService");
        }

    通过手动的形式,从spring的容器中获取相应的bean.

    参考:

    http://blog.csdn.net/qq_32588349/article/details/51793822

  • 相关阅读:
    time模块
    Python进程模块
    Django面试题
    基本命令行语句
    scrapy中的配置与中间件
    JSON编码于解码对应dump于load
    python操作数据库
    Python里的方法
    正则表达式
    Python常用模块
  • 原文地址:https://www.cnblogs.com/chihirotan/p/6420712.html
Copyright © 2011-2022 走看看