@ -589,8 +589,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
@@ -589,8 +589,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
this . readWriteLock . writeLock ( ) . lock ( ) ;
try {
HandlerMethod handlerMethod = createHandlerMethod ( handler , method ) ;
assertMappedPathMethodMapping ( handlerMethod , mapping ) ;
assertUniqueMethodMapping ( handlerMethod , mapping ) ;
validateMethodMapping ( handlerMethod , mapping ) ;
this . mappingLookup . put ( mapping , handlerMethod ) ;
List < String > directUrls = getDirectUrls ( mapping ) ;
@ -616,28 +615,23 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
@@ -616,28 +615,23 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
}
}
/ * *
* Assert that the supplied { @code mapping } maps the supplied { @link HandlerMethod }
* to explicit , non - empty paths .
* @since 5 . 2
* @see StringUtils # hasText ( String )
* /
private void assertMappedPathMethodMapping ( HandlerMethod handlerMethod , T mapping ) {
private void validateMethodMapping ( HandlerMethod handlerMethod , T mapping ) {
// Assert that the supplied mapping maps the supplied HandlerMethod
// to explicit, non-empty paths.
if ( ! getMappingPathPatterns ( mapping ) . stream ( ) . allMatch ( StringUtils : : hasText ) ) {
throw new IllegalStateException ( String . format ( "Missing path mapping. " +
"Handler method '%s' in bean '%s' must be mapped to a non-empty path. " +
"If you wish to map to all paths, please map explicitly to \"/**\" or \"**\"." ,
handlerMethod , handlerMethod . getBean ( ) ) ) ;
handlerMethod , handlerMethod . getBean ( ) ) ) ;
}
}
private void assertUniqueMethodMapping ( HandlerMethod newHandlerMethod , T mapping ) {
HandlerMethod h andlerMethod = this . mappingLookup . get ( mapping ) ;
if ( h andlerMethod ! = null & & ! h andlerMethod. equals ( newH andlerMethod) ) {
// Assert that the supplied mapping is unique.
HandlerMethod existingH andlerMethod = this . mappingLookup . get ( mapping ) ;
if ( existingH andlerMethod ! = null & & ! existingH andlerMethod. equals ( h andlerMethod) ) {
throw new IllegalStateException (
"Ambiguous mapping. Cannot map '" + newH andlerMethod . getBean ( ) + "' method \n" +
newH andlerMethod + "\nto " + mapping + ": There is already '" +
h andlerMethod. getBean ( ) + "' bean method\n" + h andlerMethod + " mapped." ) ;
"Ambiguous mapping. Cannot map '" + h andlerMethod . getBean ( ) + "' method \n" +
h andlerMethod + "\nto " + mapping + ": There is already '" +
existingH andlerMethod. getBean ( ) + "' bean method\n" + existingH andlerMethod + " mapped." ) ;
}
}