Class MicronautFactory
- java.lang.Object
-
- io.micronaut.configuration.picocli.MicronautFactory
-
- All Implemented Interfaces:
java.lang.AutoCloseable,picocli.CommandLine.IFactory
public class MicronautFactory extends java.lang.Object implements picocli.CommandLine.IFactory, java.lang.AutoCloseableAnApplicationContext-based implementation of the picocliIFactoryinterface.Specifying this factory when instantiating a
CommandLineor invoking theCommandLine.runorCommandLine.callmethods 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 aMicronautFactorywith the result of callingApplicationContext.run("cli").MicronautFactory(io.micronaut.context.ApplicationContext applicationContext)Constructs aMicronautFactorywith the specifiedApplicationContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlyingApplicationContext.<K> Kcreate(java.lang.Class<K> cls)Delegates to theApplicationContextto either find or instantiate a bean of the specified type.
-
-
-
Constructor Detail
-
MicronautFactory
public MicronautFactory()
Constructs aMicronautFactorywith the result of callingApplicationContext.run("cli").
-
MicronautFactory
public MicronautFactory(io.micronaut.context.ApplicationContext applicationContext)
Constructs aMicronautFactorywith the specifiedApplicationContext.- 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.ExceptionDelegates to theApplicationContextto either find or instantiate a bean of the specified type.- Specified by:
createin interfacepicocli.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 existsjava.lang.Exception- if a problem occurred during lookup or instantiation
-
close
public void close()
Closes the underlyingApplicationContext.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-