shiro 初始化realm注入bean失败
shiro realm注入bean失败
原因:shiro初始化realm时,springMVC还未加载相关业务Bean,导致注入失败
网上的解决方法大多是将web.xml中DispatcherServlet的load-on-startup设置为1,保证首先加载DispatcherServlet。
web.xml文件:
我试了是不行。
看下我之前的配置
dispatcher-servlet.xml
applicationContext.xml
我的shiro配置是配置在shior-config.xml文件中的。所以应该是加载applicationContext.xml时加载的shiro realm。<context:component-scan base-package="com.jing.oa.**"/>
是加载spring的bean。所以将 component-sacn 提到applicationContext.xml中即可解决bean加载问题。
更该后applicationContext.xml文件
将component-scan移出dispatcher-servlet.xml会导致Controller层加载不到,路径请求404问题,dispatcher-servlet.xml修改为如下:
至此,问题解决。