Class MicronautFactory

  • All Implemented Interfaces:
    java.lang.AutoCloseable, picocli.CommandLine.IFactory

    public class MicronautFactory
    extends java.lang.Object
    implements picocli.CommandLine.IFactory, java.lang.AutoCloseable
    An ApplicationContext-based implementation of the picocli IFactory interface.

    Specifying this factory when instantiating a CommandLine or invoking the CommandLine.run or CommandLine.call methods allows picocli to leverage Micronaut dependency injection.

    Closing this factory will close the underlying ApplicationContext.

    Since:
    1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      MicronautFactory()
      Constructs a MicronautFactory with the result of calling ApplicationContext.run("cli").
      MicronautFactory​(io.micronaut.context.ApplicationContext applicationContext)
      Constructs a MicronautFactory with the specified ApplicationContext.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying ApplicationContext.
      <K> K create​(java.lang.Class<K> cls)
      Delegates to the ApplicationContext to either find or instantiate a bean of the specified type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MicronautFactory

        public MicronautFactory()
        Constructs a MicronautFactory with the result of calling ApplicationContext.run("cli").
      • MicronautFactory

        public MicronautFactory​(io.micronaut.context.ApplicationContext applicationContext)
        Constructs a MicronautFactory with the specified ApplicationContext.
        Parameters:
        applicationContext - the context to use to look up or instantiate beans
    • Method Detail

      • create

        public <K> K create​(java.lang.Class<K> cls)
                     throws java.lang.Exception
        Delegates to the ApplicationContext to either find or instantiate a bean of the specified type.
        Specified by:
        create in interface picocli.CommandLine.IFactory
        Type Parameters:
        K - the type of the bean to return
        Parameters:
        cls - the class of the bean to return
        Returns:
        an instance of the specified class
        Throws:
        io.micronaut.context.exceptions.NoSuchBeanException - if no bean of the specified type exists
        java.lang.Exception - if a problem occurred during lookup or instantiation
      • close

        public void close()
        Closes the underlying ApplicationContext.
        Specified by:
        close in interface java.lang.AutoCloseable