SEVERE: Exception starting filter ShiroFilter error

浪子不回头ぞ 提交于 2021-02-11 15:23:32

问题


I'm developing a web application in which I have to use Shiro Apache for users and roles management.

I'm cofiguring web.xml file and I got the next error when I try to run the server.

SEVERE: Exception starting filter ShiroFilter error   
 javax.servlet.ServletException: org.apache.shiro.env.RequiredTypeException: Object named 'filterChainResolver' is not of required type [org.apache.shiro.web.filter.mgt.FilterChainResolver].
    at org.apache.shiro.web.servlet.AbstractFilter.init(AbstractFilter.java:105)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:104)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4427)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5067)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
Caused by: org.apache.shiro.env.RequiredTypeException: Object named 'filterChainResolver' is not of required type [org.apache.shiro.web.filter.mgt.FilterChainResolver].
    at org.apache.shiro.env.DefaultEnvironment.getObject(DefaultEnvironment.java:150)
    at org.apache.shiro.web.env.DefaultWebEnvironment.getFilterChainResolver(DefaultWebEnvironment.java:45)
    at org.apache.shiro.web.servlet.ShiroFilter.init(ShiroFilter.java:77)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.onFilterConfigSet(AbstractShiroFilter.java:152)
    at org.apache.shiro.web.servlet.AbstractFilter.init(AbstractFilter.java:97)
    ... 33 more

I read that this issue is probably caused by a blank shiro.ini file, isn't it? But the problem is that my file is not a blank file. Here is my web.xml file

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">


  <display-name>TFG</display-name>

<welcome-file-list>
   <welcome-file>loginPage.jsp</welcome-file>
</welcome-file-list>


<listener>
     <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>


<!--  
<context-param>
        <param-name>shiroConfigLocations</param-name>
        <param-value>WebContent/WEB-INF/shiro.ini</param-value>
</context-param>
-->



<filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>


<filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>


</web-app>

I'm not using:

<context-param>
        <param-name>shiroConfigLocations</param-name>
        <param-value>WebContent/WEB-INF/shiro.ini</param-value>
</context-param>

Because it doesn't work, when I try to use it, I got a File Not Found error and I don't know if it is due to a bad classpath definition.

I have the next classpath:

click here to see


回答1:


My shiro.ini file was:

# =============================================================================
# Tutorial INI configuration
#
# Usernames/passwords are based on the classic Mel Brooks' film "Spaceballs" :)
# =============================================================================


[main]
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager

securityManager.sessionManager = $sessionManager


# -----------------------------------------------------------------------------
# Users and their (optional) assigned roles
# username = password, role1, role2, ..., roleN
# -----------------------------------------------------------------------------

[users]
user = 1234,gestor
user2 = 1234,editor


# -----------------------------------------------------------------------------
# Roles with assigned permissions
# roleName = perm1, perm2, ..., permN
# -----------------------------------------------------------------------------



[roles]
profesor = *
gestor = *

I fixed the issue by adding:

filterChainResolver = org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver

In the main part of my shiro.ini file.



来源:https://stackoverflow.com/questions/54960713/severe-exception-starting-filter-shirofilter-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!