Annotation Interface OfMDC


@Retention(RUNTIME) @Target({METHOD,PARAMETER}) public @interface OfMDC
Specifies the binding point for a SLF4J MDC value. The annotation can be applied on both the client side, i.e., ByJms interfaces, and the server side, i.e., ForJmsType classes.

On the client side, applied to a parameter on a ByJms interface, it specifies the key and value for MDC.

On the server side, applied to a parameter of a ForJmsType Invoking method, it specifies the supplier parameter for the value of the named context.

When applied to a parameter, the context value will be supplied by the argument via Object.toString().

The annotation can also be applied to a supplier method defined by the type of the body parameter on either the client side and the server side. The supplier method must

  • be declared on the type directly, no recursion or inheritance
  • public
  • have no parameter
  • return a value
The return value, if not null, will be converted to String via Object.toString(). If no name is specified by the annotation, the method name will be used as the context key.

Note that there is only one MDC for each thread. If there is an existing context on the thread, it will be overwritten by the new value from the annotation. After execution, the all keys will be removed resulting the lose of the original values.

In case of a name collision, the following defines the precedence from high to low:

  • supplier methods from body argument
  • body argument itself
  • other arguments, e.g., headers and properties
Since:
3.0.0
Author:
Lei Yang
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies the operation of the annotation.
    Specifies the name of the MDC.
  • Element Details

    • value

      String value
      Specifies the name of the MDC.

      When no value is specified, the context name is inferred from the parameter name. For this to work properly, '-parameters' compiler option is desired.

      Default:
      ""
    • op

      Specifies the operation of the annotation.
      Default:
      Default