- 错误的配置方案及日志
<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后有没有做其它事,可从日志中细细看来。最主要的原因是配置文件加载顺序的问题