public class MicronautFactory extends Object implements picocli.CommandLine.IFactory, AutoCloseable
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
.
Constructor and Description |
---|
MicronautFactory()
Constructs a
MicronautFactory with the result of calling
ApplicationContext.run("cli") . |
MicronautFactory(ApplicationContext applicationContext)
Constructs a
MicronautFactory with the specified ApplicationContext . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the underlying
ApplicationContext . |
<K> K |
create(Class<K> cls)
Delegates to the
ApplicationContext to either find or instantiate a bean of the specified type. |
public MicronautFactory()
MicronautFactory
with the result of calling
ApplicationContext.run("cli")
.public MicronautFactory(ApplicationContext applicationContext)
MicronautFactory
with the specified ApplicationContext
.applicationContext
- the context to use to look up or instantiate beanspublic <K> K create(Class<K> cls) throws Exception
ApplicationContext
to either find or instantiate a bean of the specified type.create
in interface picocli.CommandLine.IFactory
K
- the type of the bean to returncls
- the class of the bean to returnNoSuchBeanException
- if no bean of the specified type existsException
- if a problem occurred during lookup or instantiationpublic void close() throws Exception
ApplicationContext
.close
in interface AutoCloseable
Exception
- if the underlying application context could not be closed