报错结构如下:Exception starting filter shiroFilter,但Fileter的配置路劲都是正常的,不知道为什么会出错
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- Shiro的核心安全接口,这个属性是必须的 -->
<property name="securityManager" ref="securityManager" />
<!-- 自定义shiro 的 Filter -->
<property name="filters">
<util:map>
<!-- key 定义 Filter的别名,而 value-ref 对应上面bean的id -->
<entry key="statelessAuth" value-ref="statelessAuthFilter" />
</util:map>
</property>
<!-- 要求登录时的链接(可根据项目的URL进行替换),非必须的属性,默认会自动寻找Web工程根目录下的"/login.html"页面 -->
<property name="loginUrl" value="/loginException" />
<!-- 登录成功后要跳转的连接 -->
<property name="successUrl" value="/" />
<!-- 用户访问未对其授权的资源时,所显示的连接 -->
<!-- 若想更明显的测试此属性可以修改它的值 -->
<property name="unauthorizedUrl" value="/authorizedException" />
<!-- Shiro连接约束配置,即过滤链的定义 -->
<!-- 此处可配合我的这篇文章来理解各个过滤连的作用http://blog.csdn.net/jadyer/article/details/12172839 -->
<!-- 下面value值的第一个'/'代表的路径是相对于HttpServletRequest.getContextPath()的值来的 -->
<!-- anon:它对应的过滤器里面是空的,什么都没做,这里.do和.jsp后面的*表示参数,比方说login.jsp?main这种 -->
<!-- authc:该过滤器下的页面必须验证后才能访问,它是Shiro内置的一个拦截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter -->
<property name="filterChainDefinitions">
<value>
/api/pay/notify=anon
/api/pay/ali/notify=anon
/upload/**=anon
/=anon
/index=anon
/index.html=anon
/sys/login=anon
/api/login=anon
/api/login/buyer=anon
/guest/login=anon
/captcha=anon
/api/**=statelessAuth
/**=authc,statelessAuth
</value>
</property>
</bean>
web.xml
<!-- 加载spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- shiro的filter -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>shiroFilter</param-value>
</init-param>
</filter>
初始化参数怎么是这个bean自己呢?
1、错误分析:报的错误是NOSuchBeanDefinitionException。说明spring的ioc时候没用找到shiroFilter的bean定义,那可能的原因是配置出错了,或者是配置没加载到。
2、我看了一下你web.xml配置,你加载的spring配置文件是这样的classpath:spring/applicationContext-*.xml,但是你定义的shiroFilter的bean是不是application-shiro.xml中,这样的话就会导致你的这个shiroFilter的bean没有被spring的ioc解析加载。所以就会报NOSuchBeanDefinitionException错。
3、解决方法:可以将web.xml配置改一下加载spring目录下所有得xml,或者是把这个application-shiro.xml改写名让他符合web.xml定义的加载配置路径
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/*.xml</param-value>
</context-param>
4、建议:了解下org.springframework.web.filter.DelegatingFilterProxy的含义,当filter-name和bean定义的名一样的时候targetBeanName这个初始参数就可以不用配置了
参考一下https://blog.csdn.net/allway2/article/details/97926975
https://www.cnblogs.com/Python-K8S/p/14109992.html
可能是否导包出问题了,有可能出现相同的类名的情况,系统自动导入的不正确
可能是否导包出问题了,有可能出现相同的类名的情况,系统自动导入的不正确
参考一下:
https://blog.csdn.net/weixin_30367543/article/details/97508801
https://www.cnblogs.com/coolzdp/articles/8835063.html