Log warning if multiple @RequestMapping annotations are declared
If multiple request mapping annotations are discovered, Spring MVC and
Spring WebFlux now log a warning similar to the following (without
newlines).
Multiple @RequestMapping annotations found on
void org.example.MyController.put(), but only the first will be used:
[
@org.springframework.web.bind.annotation.PutMapping(consumes={}, headers={}, name="", params={}, path={"/put"}, produces={}, value={"/put"}),
@org.springframework.web.bind.annotation.PostMapping(consumes={}, headers={}, name="", params={}, path={"/put"}, produces={}, value={"/put"})
]
Closes gh-31962
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <p>Specifically, {@code @DeleteMapping} is a <em>composed annotation</em> that
|
||||
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.DELETE)}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This annotation cannot be used in conjunction with
|
||||
* other {@code @RequestMapping} annotations that are declared on the same method.
|
||||
* If multiple {@code @RequestMapping} annotations are detected on the same method,
|
||||
* a warning will be logged, and only the first mapping will be used. This applies
|
||||
* to {@code @RequestMapping} as well as composed {@code @RequestMapping} annotations
|
||||
* such as {@code @GetMapping}, {@code @PostMapping}, etc.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.3
|
||||
* @see GetMapping
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <p>Specifically, {@code @GetMapping} is a <em>composed annotation</em> that
|
||||
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.GET)}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This annotation cannot be used in conjunction with
|
||||
* other {@code @RequestMapping} annotations that are declared on the same method.
|
||||
* If multiple {@code @RequestMapping} annotations are detected on the same method,
|
||||
* a warning will be logged, and only the first mapping will be used. This applies
|
||||
* to {@code @RequestMapping} as well as composed {@code @RequestMapping} annotations
|
||||
* such as {@code @PutMapping}, {@code @PostMapping}, etc.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.3
|
||||
* @see PostMapping
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <p>Specifically, {@code @PatchMapping} is a <em>composed annotation</em> that
|
||||
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.PATCH)}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This annotation cannot be used in conjunction with
|
||||
* other {@code @RequestMapping} annotations that are declared on the same method.
|
||||
* If multiple {@code @RequestMapping} annotations are detected on the same method,
|
||||
* a warning will be logged, and only the first mapping will be used. This applies
|
||||
* to {@code @RequestMapping} as well as composed {@code @RequestMapping} annotations
|
||||
* such as {@code @GetMapping}, {@code @PostMapping}, etc.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.3
|
||||
* @see GetMapping
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <p>Specifically, {@code @PostMapping} is a <em>composed annotation</em> that
|
||||
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.POST)}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This annotation cannot be used in conjunction with
|
||||
* other {@code @RequestMapping} annotations that are declared on the same method.
|
||||
* If multiple {@code @RequestMapping} annotations are detected on the same method,
|
||||
* a warning will be logged, and only the first mapping will be used. This applies
|
||||
* to {@code @RequestMapping} as well as composed {@code @RequestMapping} annotations
|
||||
* such as {@code @GetMapping}, {@code @PutMapping}, etc.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.3
|
||||
* @see GetMapping
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <p>Specifically, {@code @PutMapping} is a <em>composed annotation</em> that
|
||||
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.PUT)}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This annotation cannot be used in conjunction with
|
||||
* other {@code @RequestMapping} annotations that are declared on the same method.
|
||||
* If multiple {@code @RequestMapping} annotations are detected on the same method,
|
||||
* a warning will be logged, and only the first mapping will be used. This applies
|
||||
* to {@code @RequestMapping} as well as composed {@code @RequestMapping} annotations
|
||||
* such as {@code @GetMapping}, {@code @PostMapping}, etc.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.3
|
||||
* @see GetMapping
|
||||
|
||||
@@ -54,6 +54,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* {@link PutMapping @PutMapping}, {@link DeleteMapping @DeleteMapping}, or
|
||||
* {@link PatchMapping @PatchMapping}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This annotation cannot be used in conjunction with
|
||||
* other {@code @RequestMapping} annotations that are declared on the same element
|
||||
* (class, interface, or method). If multiple {@code @RequestMapping} annotations
|
||||
* are detected on the same element, a warning will be logged, and only the first
|
||||
* mapping will be used. This also applies to composed {@code @RequestMapping}
|
||||
* annotations such as {@code @GetMapping}, {@code @PostMapping}, etc.
|
||||
*
|
||||
* <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
|
||||
* make sure to consistently put <i>all</i> your mapping annotations — such
|
||||
* as {@code @RequestMapping} and {@code @SessionAttributes} — on
|
||||
|
||||
Reference in New Issue
Block a user