2

Spring-Boot アプリケーションで WebJars-Locator を使用して、JAR リソースをマップしようとしています。彼らのウェブサイトに従って、次のような RequestMapping を作成しました。

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/webjars-locator/{webjar}/{partialPath:.+}")
public ResponseEntity<ClassPathResource> locateWebjarAsset(@PathVariable String webjar, @PathVariable String partialPath)
{

これの問題は、partialPath 変数が 3 番目のスラッシュの後に何かを含めることになっていることです。ただし、最終的に行うことは、マッピング自体を制限することです。この URI は正しくマッピングされています。

http://localhost/webjars-locator/angular-bootstrap-datetimepicker/datetimepicker.js

しかし、これはハンドラーにまったくマップされておらず、単純に 404 を返します。

http://localhost/webjars-locator/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css

基本的な違いは、正規表現 (".+") で処理する必要があるパス内のコンポーネントの数ですが、その部分にスラッシュがあると機能していないように見えます。

それが役立つ場合、これはログに提供されます。

2015-03-03 23:03:53.588 INFO 15324 --- [メイン] swsmmaRequestMappingHandlerMapping: マップされた "{[/webjars-locator/{webjar}/{partialPath:.+}]、methods=[GET]、params=[ ],headers=[],consumes=[],produces=[],custom=[]}" を public org.springframework.http.ResponseEntity app.controllers.WebJarsLocatorController.locateWebjarAsset(java.lang.String,java.lang.文字列) 2

RequestMappings で正規表現パターン マッチングを有効にするために、Spring-Boot に何らかの非表示の設定がありますか?

4

2 に答える 2

1

PathVariable「URLの残りの部分」と一致させることはできないようです。ここで説明されているように、ant スタイルのパス パターン、つまり「**」を使用する必要があります。

Spring 3 RequestMapping: パス値を取得する

その後、リクエスト オブジェクトの URL 全体を取得し、「残りの部分」を抽出できます。

于 2015-03-04T12:02:28.870 に答える