本文介绍了严重:异常启动过滤器ShiroFilter错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序,其中必须使用Shiro Apache进行用户和角色管理.

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

我正在配置web.xml文件,尝试运行服务器时遇到下一个错误.

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

我读到这个问题可能是由空白的shiro.ini文件引起的,不是吗?但是问题是我的文件不是空白文件.这是我的web.xml文件

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>

我没有使用:

<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.

我有下一个类路径:

推荐答案

我的 shiro.ini 文件为:

# =============================================================================
# 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

在我的 shiro.ini 文件的主要部分.

In the main part of my shiro.ini file.

这篇关于严重:异常启动过滤器ShiroFilter错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 02:34