shiro中的service无法注入

  1. 错误的配置方案及日志
<context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:spring/applicationContext.xml</param-value>
   </context-param>
   <servlet>
       <servlet-name>dispatcher</servlet-name>
       <servlet-class>
           org.springframework.web.servlet.DispatcherServlet
       </servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:spring/applicationContext-mvc.xml</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>
   在applicationContext.xml中的末尾加入了
   <import resource="applicationContext-shiro.xml"></import>
17:38:44,108  INFO XmlBeanDefinitionReader:317 
    - Loading XML bean definitions from class path resource                         "[spring/applicationContext.xml]"
   17:38:44,489  INFO LoggerFactory:? - using logger:                                   com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
   17:38:44,525  INFO XmlBeanDefinitionReader:317 
    - Loading XML bean definitions from class path resource                         "[spring/applicationContext-shiro.xml]"
   17:38:44,677  INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker:309 
    - Bean 'myRealm' of type 
    [class com.demo.auth.AuthRealm] 
    is not eligible for getting processed by all BeanPostProcessors 
    (for example: not eligible for auto-proxying)
   17:38:44,714  INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker:309 
    - Bean 'securityManager' of type 
    [class org.apache.shiro.web.mgt.DefaultWebSecurityManager] 
    is not eligible for getting processed by all BeanPostProcessors 
    (for example: not eligible for auto-proxying)
   17:38:44,728  INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker:309 
    - Bean 'authFilter' of type 
    [class com.demo.auth.AuthFilter] 
    is not eligible for getting processed by all BeanPostProcessors 
    (for example: not eligible for auto-proxying)
   17:38:45,063  INFO ContextLoader:325 
       - Root WebApplicationContext: initialization completed in 1141 ms
   八月 27, 2018 5:38:45 下午 org.apache.catalina.core.ApplicationContext log
   信息: Initializing Spring FrameworkServlet 'dispatcher'
   17:38:45,125  INFO DispatcherServlet:484 
       - FrameworkServlet 'dispatcher': initialization started
   17:38:45,125  INFO XmlWebApplicationContext:510 
       - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': 
    startup date [Mon Aug 27 17:38:45 CST 2018]; 
    parent: Root WebApplicationContext
   17:38:45,125  INFO XmlBeanDefinitionReader:317 
       - Loading XML bean definitions from class path resource                      "[spring/applicationContext-mvc.xml]"
   17:38:45,408  INFO AutowiredAnnotationBeanPostProcessor:153 
       - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

2.正确的配置

<context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:spring/applicationContext*.xml</param-value>
   </context-param>
   <servlet>
       <servlet-name>dispatcher</servlet-name>
       <servlet-class>
           org.springframework.web.servlet.DispatcherServlet
       </servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:spring/applicationContext-mvc.xml</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>
   上面的用*代替
   在applicationContext.xml中的删除以下部分
   <import resource="applicationContext-shiro.xml"></import>
17:54:18,148  INFO XmlWebApplicationContext:510 
       - Refreshing Root WebApplicationContext: startup date 
       [Mon Aug 27 17:54:18 CST 2018]; root of context hierarchy
   17:54:18,209  INFO XmlBeanDefinitionReader:317 
       - Loading XML bean definitions from file                                         [D:\Desktop\target\classes\spring\applicationContext-mvc.xml]
   17:54:18,617  INFO XmlBeanDefinitionReader:317 
       - Loading XML bean definitions from file                                         [D:\Desktop\target\classes\spring\applicationContext-shiro.xml]
   17:54:18,661  INFO XmlBeanDefinitionReader:317 
       - Loading XML bean definitions from file                                         [D:\Desktop\target\classes\spring\applicationContext.xml]
   17:54:18,714  INFO LoggerFactory:? - using logger:                                   com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
   17:54:18,913  INFO AutowiredAnnotationBeanPostProcessor:153 
       - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
以上两种区别主要在加载完shiro.xml后有没有做其它事,可从日志中细细看来。最主要的原因是配置文件加载顺序的问题
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值