ExceptionAdviser class final

Internal representation of a @ControllerAdvice or @RestControllerAdvice declaration in Jetleaf.

A ExceptionAdviser encapsulates:

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 types
  • basePackages → applies only to controllers within those packages
  • annotations → applies only to controllers annotated with the listed annotations

Matching Rules

Advice applicability is determined in the following order:

  1. Advice–Controller type compatibility
    • A @ControllerAdvice only applies to @Controller or WebView-annotated controllers.
    • A @RestControllerAdvice only applies to @RestController-annotated controllers.
  2. Assignable types (if defined)
  3. Base packages (if defined)
  4. Annotations (if defined)
  5. 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 @ControllerAdvice or @RestControllerAdvice declaration 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 Class object 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