Class Microservice.Builder
- All Implemented Interfaces:
BeanStoreOverridable<Microservice.Builder>
- Enclosing class:
- Microservice
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor.protectedBuilder(Microservice.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionSpecifies the command-line arguments passed into the Java command.Specifies the command-line arguments passed into the Java command.beanStore(WritableBeanStore beanStore) Specifies an externalWritableBeanStoreto use instead of constructing a fresh one.build()Instantiate a new microservice using the settings defined on this builder.Specifies the config for initializing this microservice.configName(String configName) Specifies the config name for initializing this microservice.configStore(ConfigStore configStore) Specifies the config store to use for storing and retrieving configurations.configurations(Class<?>... configurations) Registers one or more@Configuration -annotated classes whose@Bean methods/fields will be processed during microservice bootstrap.configurations(List<Class<?>> configurations) Registers one or more@Configuration -annotated classes.console(Scanner consoleReader, PrintWriter consoleWriter) Specifies the console input and output.consoleCommands(Class<? extends ConsoleCommand>... consoleCommands) Specifies console commands to make available on the Java console.consoleCommands(ConsoleCommand... consoleCommands) Specifies console commands to make available on the Java console.consoleEnabled(boolean consoleEnabled) Specifies that the Java console is enabled for this microservice.copy()Creates a copy of this builder.voidinitWorkingDirFromEnv(String workingDirEnv) @Inject-annotated initializer that populatesworkingDirfrom thejuneau.workingDirproperty (system property → environment variable → registered property sources) when the property is set.listener(MicroserviceListener listener) Registers an event listener for this microservice.Specifies logging instructions for the microservice.Specifies the logger used by the microservice and returned by theMicroservice.getLogger()method.Specifies the manifest file of the jar file this microservice is contained within.overridingBeanStore(BeanStore store) Installs the suppliedBeanStoreas theoverridingParentof this microservice's bean store.protected FileresolveFile(String path) Resolves the specified path.Adds a bean for vars defined in the var resolver.Augments the set of variables defined in the configuration and var resolver.workingDir(File workingDir) Specifies the directory to use to resolve the config file and other paths defined with the config file.workingDir(String workingDir) Specifies the directory to use to resolve the config file and other paths defined with the config file.
-
Constructor Details
-
Builder
protected Builder()Constructor. -
Builder
Copy constructor.- Parameters:
copyFrom- The builder to copy.
-
-
Method Details
-
initWorkingDirFromEnv
@Inject-annotated initializer that populatesworkingDirfrom thejuneau.workingDirproperty (system property → environment variable → registered property sources) when the property is set. Has no effect ifworkingDirwas already set programmatically.- Parameters:
workingDirEnv- The resolvedjuneau.workingDirvalue, ornull/empty when not configured.
-
args
Specifies the command-line arguments passed into the Java command.This is required if you use
Microservice.getArgs()or$A string variables. -
args
Specifies the command-line arguments passed into the Java command.This is required if you use
Microservice.getArgs()or$A string variables.- Parameters:
args- The command-line arguments passed into the Java command as the raw command-line arguments.- Returns:
- This object.
-
build
Instantiate a new microservice using the settings defined on this builder.- Returns:
- A new microservice.
- Throws:
Exception- Error occurred.
-
config
Specifies the config for initializing this microservice.Calling this method overrides the default configuration controlled by the
configName(String)andconfigStore(ConfigStore)methods.- Parameters:
config- The configuration. Can benull (the configuration is auto-resolved).- Returns:
- This object.
-
configName
Specifies the config name for initializing this microservice.If you do not specify the config file location, we attempt to resolve it through the following methods:
-
Resolve file first in working directory, then in classpath, using the following names:
-
The
"configFile" argument in the command line arguments passed in through the constructor. -
The value of the
Main-Config entry in the manifest file. -
A config file in the same location and with the same name as the executable jar file.
(e.g.
"java -jar myjar.jar" will look for"myjar.cfg" ).
-
The
-
Resolve any
"*.cfg" file that can be found in the working directory. -
Resolve any of the following files in the classpath:
"juneau.cfg" ,"system.cfg"
If no configuration file is found, and empty in-memory configuration is used.
- Parameters:
configName- The configuration name. Can benull (the configuration name is auto-resolved).- Returns:
- This object.
-
Resolve file first in working directory, then in classpath, using the following names:
-
configStore
Specifies the config store to use for storing and retrieving configurations.By default, we use a
FileStorestore for configuration files.- Parameters:
configStore- The configuration store. Can benull (a defaultFileStoreis used).- Returns:
- This object.
-
console
Specifies the console input and output.If not specified, uses the console returned by
System.console(). If that is not available, usesSystem.inandSystem.out.Note that these are ignored if the console is not enabled via
consoleEnabled(boolean).- Parameters:
consoleReader- The console input. Can benull (the default console input is used).consoleWriter- The console output. Can benull (the default console output is used).- Returns:
- This object.
-
consoleCommands
public Microservice.Builder consoleCommands(Class<? extends ConsoleCommand>... consoleCommands) throws ExecutableException Specifies console commands to make available on the Java console.Note that these are ignored if the console is not enabled via
consoleEnabled(boolean).This list augments the commands defined via the
"Console/commands" configuration setting.This method can only be used on console commands with no-arg constructors.
- Parameters:
consoleCommands- The list of console commands to append to the list of available commands.- Returns:
- This object.
- Throws:
ExecutableException- Exception occurred on invoked constructor/method/field.
-
consoleCommands
Specifies console commands to make available on the Java console.Note that these are ignored if the console is not enabled via
consoleEnabled(boolean).This list augments the commands defined via the
"Console/commands" configuration setting.- Parameters:
consoleCommands- The list of console commands to append to the list of available commands.- Returns:
- This object.
-
consoleEnabled
Specifies that the Java console is enabled for this microservice.If not specified, this value is taken from the
"Console/enabled" configuration setting. If not specified in the configuration, defaults tofalse .- Parameters:
consoleEnabled-true if the Java console is enabled for this microservice.- Returns:
- This object.
-
copy
Creates a copy of this builder.- Returns:
- A new copy of this builder.
-
listener
Registers an event listener for this microservice.- Parameters:
listener- An event listener for this microservice. Can benull (no listener is registered).- Returns:
- This object.
-
logConfig
Specifies logging instructions for the microservice.If not specified, the values are taken from the
"Logging" section of the configuration.This method is ignored if
logger(Logger)is used to set the microservice logger.- Parameters:
logConfig- The log configuration. Can benull (a defaultLogConfigis used).- Returns:
- This object.
-
logger
Specifies the logger used by the microservice and returned by theMicroservice.getLogger()method.Calling this method overrides the default logging mechanism controlled by the
logConfig(LogConfig)method.- Parameters:
logger- The logger to use for logging microservice messages. Can benull (a default logger is created).- Returns:
- This object.
-
manifest
Specifies the manifest file of the jar file this microservice is contained within.This is required if you use
Microservice.getManifest(). It's also used to locate initialization values such asMain-Config .If you do not specify the manifest file, we attempt to resolve it through the following methods:
-
Looking on the file system for a file at
"META-INF/MANIFEST.MF" . This is primarily to allow for running microservices from within eclipse workspaces where the manifest file is located in the project root. -
Using the class loader for this class to find the file at the URL
"META-INF/MANIFEST.MF" .
- Parameters:
value- The manifest file of this microservice.
Can be any of the following types:ManifestFileManifestReader- Containing the raw contents of the manifest. Note that the input must end with a newline.InputStream- Containing the raw contents of the manifest. Note that the input must end with a newline.File- File containing the raw contents of the manifest.String- Path to file containing the raw contents of the manifest.Class- Finds and loads the manifest file of the jar file that the specified class is contained within.
Can benull (the manifest is auto-resolved).- Returns:
- This object.
- Throws:
IOException- Thrown by underlying stream.
-
Looking on the file system for a file at
-
varBean
Adds a bean for vars defined in the var resolver.This calls
VarResolver.Builder#bean(Class,Object)on the var resolver used to construct the configuration object returned byMicroservice.getConfig()and the var resolver returned byMicroservice.getVarResolver().- Type Parameters:
T- The bean type.- Parameters:
c- The bean type.value- The bean.- Returns:
- This object.
-
vars
Augments the set of variables defined in the configuration and var resolver.This calls
VarResolver.Builder#vars(Class[])on the var resolver used to construct the configuration object returned byMicroservice.getConfig()and the var resolver returned byMicroservice.getVarResolver().- Parameters:
vars- The set of variables to append to the var resolver builder.- Returns:
- This object.
-
workingDir
Specifies the directory to use to resolve the config file and other paths defined with the config file.- Parameters:
workingDir- The working directory, ornull to use the underlying working directory.- Returns:
- This object.
-
workingDir
Specifies the directory to use to resolve the config file and other paths defined with the config file.- Parameters:
workingDir- The working directory. Must not benull .- Returns:
- This object.
-
configurations
Registers one or more@Configuration -annotated classes whose@Bean methods/fields will be processed during microservice bootstrap.Beans contributed by
@Configuration classes are stored in the microservice's internalWritableBeanStore(accessible viaMicroservice.getBeanStore()). They become available to other@Bean factory methods via constructor injection.Explicit builder calls (e.g.
config(Config),args(Args)) take precedence over@Bean -supplied values — the resolved field is registered into the bean store after configurations are processed, overwriting any same-type@Bean contribution.- Parameters:
configurations- The configuration classes. Can benull or empty (no-op);null elements are ignored.- Returns:
- This object.
- Since:
- 10.0.0
-
configurations
Registers one or more@Configuration -annotated classes.- Parameters:
configurations- The configuration classes. Can benull or empty (no-op);null elements are ignored.- Returns:
- This object.
- Since:
- 10.0.0
- See Also:
-
beanStore
Specifies an externalWritableBeanStoreto use instead of constructing a fresh one.Useful for testing and for composing a microservice into a larger application that already owns a bean store (e.g. a Spring-backed parent store). When set, configurations supplied via
configurations(Class...)are registered into this store, and the microservice's resolved values (args, manifest, config, var resolver, listener, microservice itself) are also registered into it.- Parameters:
beanStore- The external bean store. Can benull to use a fresh internal store.- Returns:
- This object.
- Since:
- 10.0.0
-
overridingBeanStore
Installs the suppliedBeanStoreas theoverridingParentof this microservice's bean store.The overlay is consulted before any locally-registered beans during construction-time reflective injection (see
BasicBeanStore(BeanStore, BeanStore)), so test-time overrides win over the microservice's own@Beanfactory contributions. This is the Mode INJECT wiring pattern forMicroservice-based tests — the overlay is installed before the microservice is constructed and lives for the microservice's full lifetime. For per-test push/pop overlays against an already-started microservice, seeMicroservice.getBeanStore()and the push/pop primitives onWritableBeanStore.Composes with
beanStore(WritableBeanStore): when both are supplied, the supplied external store becomes the regular parent and the overlay becomes the overriding parent of a fresh wrappingBasicBeanStore.- Specified by:
overridingBeanStorein interfaceBeanStoreOverridable<Microservice.Builder>- Parameters:
store- The override layer. Can benull to clear a previously-set value.- Returns:
- This object.
- Since:
- 10.0.0
-
resolveFile
Resolves the specified path.If the working directory has been explicitly specified, relative paths are resolved relative to that.
- Parameters:
path- The path to resolve. Must not benull .- Returns:
- The resolved file.
-