0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

java.lang.ClassCastException: class org.springframework.web.filter.HiddenHttpMethodFilter cannot be cast to class jakarta.servlet.Filter

Posted at

事象 : Tomcatを起動したらエラー

  • 環境
    • macOS BigSur バージョン11.3.1
    • Eclipse Version: 2020-12 (4.18.0)
    • Apache Tomcat/10.0.6
重大: フィルタ [HiddenHttpMethodFilter] の起動中の例外です
java.lang.ClassCastException: class org.springframework.web.filter.HiddenHttpMethodFilter cannot be cast to class jakarta.servlet.Filter (org.springframework.web.filter.HiddenHttpMethodFilter is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @76f7d241; jakarta.servlet.Filter is in unnamed module of loader java.net.URLClassLoader @97e1986)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:250)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
  1. EclipseでSpringBootのプロジェクトを作った
  2. パソコンにインストールしてあるTomcat10を設定
  3. Tomcat10を起動したらエラーになった
▼エラーメッセージにあるHiddenHttpMethodFilterはweb.xmlに定義していました。▼
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
    <!-- ...省略... -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.7</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>2.5.1</version>
    </dependency>
    <!-- ...省略... -->
web.xml
<?xml version="1.0" encoding="UTF-8"?>
  <!-- ...省略... -->
  <filter>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

原因 : Tomcat10だから

Don't use Tomcat 10 yet, it works with the new jakarta packages.
Switch to version 9 instead.
Wicket 9 & Tomcat 10 Can't Cast jakarta.servlet.Filter - Stack Overflow

2020年の5月ぐらい投稿のことなのに・・・・違うのかと思ったけど・・・Tomcat9にしたうまくいった。

対応 : Tomcat9に変える

  1. Tomcat9をインストールする
  2. EclipseにTomcat9を設定して起動する
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?