严重:异常springSecurityFilterChain ... ClassCastException ...无法转换DelegatingFilterProxy

时间:2011-10-10 03:31:38

标签: tomcat classcastexception

任何人都可以帮我解决我的tomcat运行错误,当我运行tomcat时出现以下错误:

SEVERE: Exception starting filter springSecurityFilterChain
java.lang.ClassCastException: org.springframework.web.filter.DelegatingFilterProxy cannot be cast to javax.servlet.Filter
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4001)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4651)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
    at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:533)
    at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:239)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

5 个答案:

答案 0 :(得分:9)

你的一个依赖项包括一个servlet-api到你的war文件中,这导致了这种行为。使用mvn dependency:tree,你可以找出你的依赖关系。之后,您需要按如下方式排除servlet-api:

<dependency>
  <groupId>[VALUE]</groupId>
  <artifactId>[VALUE]</artifactId>
  <version>[VALUE]</version>
  <exclusions>
    <exclusion>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
    </exclusion>
  </exclusions>
</dependency>

你需要为其他servlet-api(例如org.mortbay.jetty:servlet-api,..)执行此操作。

答案 1 :(得分:3)

我可以通过从部署程序集中删除servlet-api.jar来解决这个问题(在eclipse中)

MY-web的项目 - &GT;属性 - &gt;部署程序集

并删除它。其他人声明,在maven项目中,servlet-api依赖的范围必须设置为“提供”

答案 2 :(得分:1)

当我添加CXF的依赖项时,我遇到了类似的问题。我尝试了以上推荐的方法从该依赖项中排除javax.servlet,但它没有用 - 但是添加提供解决了它。 这可能是一个不同的情况,但值得一试。

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle-jaxrs</artifactId>
        <version>2.2.9</version>
        <scope>provided</scope>
    </dependency>

如果我回答了你的问题,请注明。 ;)

答案 3 :(得分:0)

通过排除geronimo解决了类似问题。

        <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>3.0.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.geronimo.specs</groupId>
                <artifactId>geronimo-servlet_2.5_spec</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.geronimo.specs</groupId>
                <artifactId>geronimo-servlet_3.0_spec</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

确定哪些jar文件包含通过扫描WEB-INF / lib文件夹中包含的类的每个jar文件找到的错误。即。

jar tvf <jar-file>

答案 4 :(得分:0)

可能在您配置的web.xml中

// The following arrays are for use with UISegmentedControl (other three removed for brevity)
// This is an array of 'Appearance' list items created from allListItems
let appearanceArray = allListItems.filter{
    $0.category.rangeOfString("Appearance") != nil
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:
    NSIndexPath) -> UITableViewCell {
    let cellIdentifier = "Cell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AllListItemsTableViewCell

    // This is a string value for the cell at indexPath.row
    var listItemInCell = ""

    // This is an array of all listItems in allListItems, and used with indexOf to check boolean status of isSelected inside of allListItems array
    let arrayAll = allListItems.map{($0.listItem)}

    // This is an array of all listItems in selectedListItems, and used to track remove indexes
    let arraySelected = selectedListItems.map{($0.listItem)}


    switch(segmentedControl.selectedSegmentIndex)
    {

    case 0: // Case 0 of 4, the others removed for brevity of this question

        listItemInCell = appearanceArray[indexPath.row].listItem

        // Index of listItemInCell inside of the array of allListItems' listItems
        let indexOf = arrayAll.indexOf(listItemInCell)!

        cell.listItemLabel.text = listItemInCell

        // Tracks UISwitch activity
        cell.callback = { (tableViewCell, switchState) in
            if self.tableView.indexPathForCell(tableViewCell) != nil {

                // do something with index path and switch state
                if switchState == true {
                    allListItems[indexOf].isSelected = true
                    selectedListItems.append(self.appearanceArray[indexPath.row])
                } else {
                    allListItems[indexOf].isSelected = false
                    let indexInSelected = arraySelected.indexOf(listItemInCell)!
                    selectedListItems.removeAtIndex(indexInSelected)
                }
            }
        }

        if appearanceArray[indexPath.row].isSelected {
            cell.toggleIsSelected.on = true
        } else {
            cell.toggleIsSelected.on = false
        }

        break

但它是过滤器。所以将servlet更改为过滤器。