Annotation Interface Guice


@Target(TYPE) @Retention(SOURCE) public @interface Guice
Annotation that can be applied to the application entry point that allows the import of Guice modules.

Micronaut will import the modules and run them at startup when the application starts registering the provided beans using the Guice DSL.

Note all features of Guice are supported, there exist the following limitations:

  1. Guice Scopes are not supported
  2. Guice AOP/Interceptors are not supported
  3. Guice private modules are not supported
  4. Static Injection is not supported
  5. Guice TypeConverters are not supported (use TypeConverter instead.
  6. Guice Listeners are not supported (use BeanCreatedEventListener instead.
  7. None of the com.google.inject.spi API is supported

Note that if you create a runtime binding to a class with LinkedBindingBuilder.to(Class) that has no injection annotations you may need to import the bean first to allow the bean to be instantiated without reflection. This can be done with Import

Otherwise it is recommended to as a minimum use the Inject annotation on the constructor to avoid this need.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<? extends com.google.inject.Module>[]
    Import the given Guice modules.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    Import the given Guice classes.
    Import the given named Guice classes.
    The environment where the modules should be active (Defaults to all environments).
    Import the given packages as guice classes.
  • Element Details

    • modules

      Class<? extends com.google.inject.Module>[] modules
      Import the given Guice modules.

      The modules are imported in the order defined by the array.

      Returns:
      An array of module types
    • classes

      Class<?>[] classes
      Import the given Guice classes.
      Returns:
      An array of classes to import
      Default:
      {}
    • classNames

      @AliasFor(member="classes") String[] classNames
      Import the given named Guice classes.
      Returns:
      An array of class names to import
      Default:
      {}
    • packages

      String[] packages
      Import the given packages as guice classes.
      Returns:
      An array of package names
      Default:
      {}
    • environments

      String[] environments
      The environment where the modules should be active (Defaults to all environments).
      Returns:
      The environments.
      Default:
      {}