- java.lang.Object
-
- picocli.spring.PicocliSpringFactory
-
- All Implemented Interfaces:
CommandLine.IFactory
public class PicocliSpringFactory extends Object implements CommandLine.IFactory
PicocliSpringFactory is aCommandLine.IFactoryimplementation that looks up classes in a givenorg.springframework.context.ApplicationContext. This allows picocli subcommands (and other objects that are instantiated as needed) to havejavax.injectannotations that will be populated by Spring's dependency injection framework.- Since:
- 4.0.0
-
-
Constructor Summary
Constructors Constructor Description PicocliSpringFactory(org.springframework.context.ApplicationContext applicationContext)Constructs a PicocliSpringFactory with the specified Application context, and picocli'sdefault factoryas the fallback factory for classes not found in the application context.PicocliSpringFactory(org.springframework.context.ApplicationContext applicationContext, CommandLine.IFactory fallbackFactory)Constructs a PicocliSpringFactory with the specified Application context, and the specified fallback factory for classes not found in the application context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <K> Kcreate(Class<K> clazz)Returns an instance of the specified class.
-
-
-
Constructor Detail
-
PicocliSpringFactory
public PicocliSpringFactory(org.springframework.context.ApplicationContext applicationContext)
Constructs a PicocliSpringFactory with the specified Application context, and picocli'sdefault factoryas the fallback factory for classes not found in the application context.- Parameters:
applicationContext- the application context to look up classes in; must be non-null
-
PicocliSpringFactory
public PicocliSpringFactory(org.springframework.context.ApplicationContext applicationContext, CommandLine.IFactory fallbackFactory)Constructs a PicocliSpringFactory with the specified Application context, and the specified fallback factory for classes not found in the application context.- Parameters:
applicationContext- the application context to look up classes in; must be non-nullfallbackFactory- the factory used to instantiate classes that are not found in the specified application context; must be non-null- Since:
- 4.7.0
-
-
Method Detail
-
create
public <K> K create(Class<K> clazz) throws Exception
Description copied from interface:CommandLine.IFactoryReturns an instance of the specified class.- Specified by:
createin interfaceCommandLine.IFactory- Type Parameters:
K- the type of the object to return- Parameters:
clazz- the class of the object to return- Returns:
- the instance
- Throws:
Exception- an exception detailing what went wrong when creating or obtaining the instance
-
-