ExceptionAdviser class final
Internal representation of a @ControllerAdvice or @RestControllerAdvice declaration in Jetleaf.
A ExceptionAdviser encapsulates:
- The annotated target instance (the object containing the advice methods)
- The advice annotation metadata (ControllerAdvice, WebView or RestControllerAdvice)
- The declaring class type for reflective access
This class determines whether the advice applies to a given controller type based on the scoping attributes of ControllerAdvice:
assignableTypes→ applies only to the specified or derived controller typesbasePackages→ applies only to controllers within those packagesannotations→ applies only to controllers annotated with the listed annotations
Matching Rules
Advice applicability is determined in the following order:
- Advice–Controller type compatibility
- A
@ControllerAdviceonly applies to@ControllerorWebView-annotated controllers. - A
@RestControllerAdviceonly applies to@RestController-annotated controllers.
- A
- Assignable types (if defined)
- Base packages (if defined)
- Annotations (if defined)
- Defaults to
true(applies globally)
Example
@ControllerAdvice(assignableTypes: [UserController])
class UserErrorAdvice {
@ExceptionHandler(UserNotFoundException)
PageView handleUserError() => PageView.of('error.html', HttpStatus.NOT_FOUND);
}
@RestControllerAdvice(assignableTypes: [ApiController])
class ApiErrorAdvice {
@ExceptionHandler(ApiException)
ResponseBody<String> handleApiError() => ResponseBody.of('API error', HttpStatus.INTERNAL_SERVER_ERROR);
}
// During runtime:
final adviser = ControllerAdviser(controllerAdvice, instance, ClassUtils.loadClass(UserErrorAdvice));
final applies = adviser.advises(ClassUtils.loadClass(UserController)); // true
Design Notes
- This class is not part of the public API; it is used internally by Jetleaf’s controller advice resolution system.
- The advice type–controller type pairing ensures that a REST advice cannot accidentally apply to a traditional MVC controller, and vice versa.
See also:
Constructors
- ExceptionAdviser(ControllerAdvice controllerAdvice, Object target, Class type)
-
Internal representation of a
@ControllerAdviceor@RestControllerAdvicedeclaration in Jetleaf.
Properties
- controllerAdvice → ControllerAdvice
-
The ControllerAdvice or RestControllerAdvice annotation attached to the target class.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- target → Object
-
The runtime instance containing the advice methods.
final
- type → Class
-
The reflective
Classobject representing the advice type.final
Methods
-
advises(
Class controllerClass) → bool -
Determines whether this advice applies to the given
controllerClass. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited