@@ -404,13 +404,14 @@ protected void registerHandler(String[] urlPaths, String beanName) throws BeansE
404
404
405
405
/**
406
406
* Register the specified handler for the given URL path.
407
+ * <p>This method may be invoked at runtime after initialization has completed.
407
408
* @param urlPath the URL the bean should be mapped to
408
409
* @param handler the handler instance or handler bean name String
409
410
* (a bean name will automatically be resolved into the corresponding handler bean)
410
411
* @throws BeansException if the handler couldn't be registered
411
412
* @throws IllegalStateException if there is a conflicting handler registered
412
413
*/
413
- protected void registerHandler (String urlPath , Object handler ) throws BeansException , IllegalStateException {
414
+ public void registerHandler (String urlPath , Object handler ) throws BeansException , IllegalStateException {
414
415
Assert .notNull (urlPath , "URL path must not be null" );
415
416
Assert .notNull (handler , "Handler object must not be null" );
416
417
Object resolvedHandler = handler ;
@@ -456,6 +457,39 @@ else if (urlPath.equals("/*")) {
456
457
}
457
458
}
458
459
460
+ /**
461
+ * Un-register the given mapping.
462
+ * <p>This method may be invoked at runtime after initialization has completed.
463
+ * @param urlPath the mapping to unregister
464
+ */
465
+ public void unregisterHandler (String urlPath ) throws IllegalArgumentException {
466
+ Assert .notNull (urlPath , "URL path must not be null" );
467
+ Object mappedHandler = this .handlerMap .get (urlPath );
468
+ if (mappedHandler != null ) {
469
+ if (urlPath .equals ("/" )) {
470
+ if (logger .isTraceEnabled ()) {
471
+ logger .trace ("Unregistered root mapping." );
472
+ }
473
+ setRootHandler (null );
474
+ }
475
+ else if (urlPath .equals ("/*" )) {
476
+ if (logger .isTraceEnabled ()) {
477
+ logger .trace ("Unregistered default mapping." );
478
+ }
479
+ setDefaultHandler (null );
480
+ }
481
+ else {
482
+ if (logger .isTraceEnabled ()) {
483
+ logger .trace ("Unregistered mapping \" " + urlPath + "\" " );
484
+ }
485
+ this .handlerMap .remove (urlPath );
486
+ if (getPatternParser () != null ) {
487
+ this .pathPatternHandlerMap .remove (getPatternParser ().parse (urlPath ));
488
+ }
489
+ }
490
+ }
491
+ }
492
+
459
493
private String getHandlerDescription (Object handler ) {
460
494
return (handler instanceof String ? "'" + handler + "'" : handler .toString ());
461
495
}
0 commit comments