Enum Around.ProxyTargetConstructorMode

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Around.ProxyTargetConstructorMode>
    Enclosing class:
    Around

    public static enum Around.ProxyTargetConstructorMode
    extends java.lang.Enum<Around.ProxyTargetConstructorMode>
    When using Around.proxyTarget() on a Factory method if the returned bean features constructor arguments this can lead to undefined behaviour since it is expected with factory methods that the developer is responsible for constructing the object.

    For example if the type accepts an argument of type String then there is no way for Micronaut to know what to inject as a value for the argument and injecting null is inherently unsafe.

    The Around.ProxyTargetConstructorMode allows the developer decide if they wish to allow proxies to be constructed and if a proxy is allowed then Micronaut will either inject a bean if it is found or null if is not. For primitive types Micronaut will inject true for booleans and 0 for number types

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      ALLOW
      Allow types to be proxied and don't print any warnings.
      ERROR
      Do not allow types with constructor arguments to be proxied.
      WARN
      Allow types to be proxied but print a warning when this feature is used.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Around.ProxyTargetConstructorMode valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static Around.ProxyTargetConstructorMode[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • ERROR

        public static final Around.ProxyTargetConstructorMode ERROR
        Do not allow types with constructor arguments to be proxied. This is the default behaviour and compilation will fail.
      • WARN

        public static final Around.ProxyTargetConstructorMode WARN
        Allow types to be proxied but print a warning when this feature is used.

        In this case if a constructor parameter cannot be injected Micronaut will inject null for objects or false for boolean or 0 for any other primitive.

    • Method Detail

      • values

        public static Around.ProxyTargetConstructorMode[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Around.ProxyTargetConstructorMode c : Around.ProxyTargetConstructorMode.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Around.ProxyTargetConstructorMode valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null