1
3

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.

デプロイ後、「PUT」「DELETE」メソッドが実行できない

Posted at

概要

ローカル環境では問題なく実行できたアプリが、Herokuにデプロイ後「DELETE」「PUT」メソッドが実行できないという事象が発生しました。

アプリケーションはspring-boot用いて作成しております。

環境 

OS: macOS Big Sur 11.2.3
JDK:14.0.1
Spring Boot 2.3.3
eclipse

結論(原因)

デプロイ先で利用するapplication.properties内に、
「spring.mvc.hiddenmethod.filter.enabled=true」が記載されていなかった。

対処法

デプロイ先で利用するapplication.properties内に、
「spring.mvc.hiddenmethod.filter.enabled=true」を追記します。

spring.datasource.url=jdbc:${DATABASE_URL}
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASS}
logging.level.jdbc=INFO
logging.level.jdbc.sqltiming=DEBUG
///追加
spring.mvc.hiddenmethod.filter.enabled=true

SpringBoot 2.1 までは、HiddenHttpMethodFilter がデフォルトで有効化されていたのですが、SpringBoot 2.2以降デフォルトでオフになり、上記のように設定で有効にしないと「PUT」「DELETE」メソッドを扱うことができなくなったようです。

ローカル環境で利用するapplication.properties内には、
「spring.mvc.hiddenmethod.filter.enabled=true」は記載されておりました。
ローカル環境では問題なく動作していたのはこれが原因でした。

参考
SpringBoot2.2+ThymeleafでHTTP PUT/DELETE メソッドを扱う

再度Herokuにデプロイし、「PUT」「DELETE」メソッドを試してみたところ、
正常に実行されました。

追記

ちなみに「spring.mvc.hiddenmethod.filter.enabled=true」の記載がない状態でHerokuで「PUT」「DELETE」メソッドを実行すると、下記のように「POST」メソッドとして処理されます。

  • 「PUT」メソッド
2021-04-22T05:24:40.286520+00:00 app[web.1]: /users
2021-04-22T05:24:40.681582+00:00 heroku[router]: at=info method=POST path="/users" host=snitch1.herokuapp.com request_id=“secret fwd="60.112.103.188" dyno=web.1 connect=1ms service=394ms status=302 bytes=393 protocol=https
  • 「DELETE」メソッド
2021-04-22T05:30:02.509773+00:00 app[web.1]: /users
2021-04-22T05:30:02.561299+00:00 heroku[router]: at=info method=POST path="/users" host=snitch1.herokuapp.com request_id=e5d41ff7-3b77-4bc5-a4db-bdb185d40d30 fwd="60.112.103.188" dyno=web.1 connect=6ms service=59ms status=200 bytes=2456 protocol=https
1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?