public class MicronautFactory
extends java.lang.Object
implements picocli.CommandLine.IFactory, java.lang.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(io.micronaut.context.ApplicationContext applicationContext)
Constructs a
MicronautFactory with the specified ApplicationContext . |
Modifier and Type | Method and 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. |
public MicronautFactory()
MicronautFactory
with the result of calling
ApplicationContext.run("cli")
.public MicronautFactory(io.micronaut.context.ApplicationContext applicationContext)
MicronautFactory
with the specified ApplicationContext
.applicationContext
- the context to use to look up or instantiate beanspublic <K> K create(java.lang.Class<K> cls) throws java.lang.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 returnio.micronaut.context.exceptions.NoSuchBeanException
- if no bean of the specified type existsjava.lang.Exception
- if a problem occurred during lookup or instantiationpublic void close()
ApplicationContext
.close
in interface java.lang.AutoCloseable