Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Cannot have an @RequestMapping and @FrameworkMapping mapped to the same endpoint with different HTTP methods

オープン
#4 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java, spring
領域
api, backend

調査の方向性

まず、CartEndpoint と CustomCartEndpoint の例を再現ケースとして使用し、DispatcherServlet を RequestMappingInfoHandlerMapping と FrameworkMappingHandlerMapping を通じて追跡します。GET マッピングによって下流の解決が妨げられる箇所を特定し、その後、説明されている workaround なしで、同等の GET および POST マッピングを両方のアノテーションにまたがって解決できることを検証します。

索引モデルが issue の本文から書いたものです。

説明

The body of this issue was copied over from BroadleafCommerce/Issues#3.

Initially reported at https://stackoverflow.com/questions/45652009/broadleaf-apis-not-working

The example where this fails is CartEndpoint. We have an extension of the Broadleaf CartEndpoint called CustomCartEndpoint in DemoSite. The problem is that we overwrote the exact same URL that exists in the API module. So we essentially have this situation:

@FrameworkMapping(value = "/cart", method = RequestMethod.POST)
 public OrderWrapper createNewCartForCustomer(HttpServletRequest request) {
    ...
}

@RequestMapping(value = "/cart", method = RequestMethod.GET)
public OrderWrapper findCartForCustomer(HttpServletRequest request) {
    ...
}

The problem is when the DispatcherServlet goes looking for a HandlerMapping to resolve the current request, it first consults the default RequestMappingInfoHandlerMapping (which is where all of the @RequestMapping endpoints go). The RequestMappingInfoHandlerMapping essentially only looks for something that matches the URL string and results in a partial mapping for the findCartForCustomer() method (which is a GET). Thus, it throws a 405 method not allowed rather than continue to send the request downstream to be handled by FrameworkMappingHandlerMapping, which is where all of the @FrameworkMapping methods are.

The workaround is to in CustomCartEndpoint in DemoSite extend the createNewCartForCustomer() method, put @RequestMapping on it and just call super. Thus, the final CustomCartEndpoint will look like:

@RestController
@RequestMapping(value = "/cart",
                produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public class CustomCartEndpoint extends CartEndpoint {

    @Override
    @RequestMapping(value = "", method = RequestMethod.GET)
    public OrderWrapper findCartForCustomer(HttpServletRequest request) {
        try {
            return super.findCartForCustomer(request);
        } catch (Exception e) {
            // if we failed to find the cart, create a new one
            return createNewCartForCustomer(request);
        }
    }
    
    @Override
    @RequestMapping(value = "", method = RequestMethod.POST)
    public OrderWrapper createNewCartForCustomer(HttpServletRequest request) {
        return super.createNewCartForCustomer(request);
    }
}
主要言語
Java
スター
2
フォーク
2
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

BroadleafCommerce/spring-frameworkmapping のほかの issue

BroadleafCommerce/spring-frameworkmapping の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。