@CompileStatic class GrailsAppBuilder extends SpringApplicationBuilder
Fluent API for constructing and running a GrailsApp: the Grails counterpart of Spring Boot's SpringApplicationBuilder.
Every builder method of SpringApplicationBuilder is available and keeps returning a
GrailsAppBuilder, so a chain stays in Grails terms from start to finish and the application
it runs is a GrailsApp with the Grails startup defaults:
new GrailsAppBuilder(Application)
.profiles('metrics')
.properties('server.port=8081')
.run(args)
Parent/child context hierarchies work as they do in Spring Boot, with every context of the
hierarchy started by a GrailsApp: child(Class[]), parent(Class[]) and
sibling(Class[]) return Grails builders, a parent cannot host an embedded web server, and
closing the parent closes its children. Exactly one context of a hierarchy is the Grails application,
the one whose sources include the Grails application class; the others are plain Spring contexts that
share the Grails beans through the parent chain. Because the parent cannot serve web requests, the
application class belongs in the child of a two-level hierarchy:
new GrailsAppBuilder(SharedConfiguration)
.child(Application)
.run(args)
| Constructor and description |
|---|
GrailsAppBuilder(java.lang.Class<?>[] sources)Create a new builder for a GrailsApp that loads beans from the given sources. |
GrailsAppBuilder(ResourceLoader resourceLoader, java.lang.Class<?>[] sources)Create a new builder for a GrailsApp that loads beans from the given sources through the given resource loader. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
GrailsAppBuilder |
addBootstrapRegistryInitializer(BootstrapRegistryInitializer bootstrapRegistryInitializer) |
|
GrailsAppBuilder |
addCommandLineProperties(boolean addCommandLineProperties) |
|
GrailsAppBuilder |
allowCircularReferences(boolean allowCircularReferences) |
|
GrailsApp |
application()
|
|
GrailsAppBuilder |
applicationStartup(ApplicationStartup applicationStartup) |
|
GrailsAppBuilder |
banner(Banner banner) |
|
GrailsAppBuilder |
bannerMode(Banner.Mode bannerMode) |
|
GrailsAppBuilder |
beanNameGenerator(BeanNameGenerator beanNameGenerator) |
|
GrailsApp |
build()
|
|
GrailsApp |
build(java.lang.String[] args)Builds the GrailsApp with the given arguments, running the parent first when this builder has one. |
|
GrailsAppBuilder |
child(java.lang.Class<?>[] sources)Creates a child of this builder whose context has the context this builder creates as its parent, as SpringApplicationBuilder.child does, except that the child is a GrailsAppBuilder running a GrailsApp. |
|
ConfigurableApplicationContext |
context() |
|
GrailsAppBuilder |
contextFactory(ApplicationContextFactory factory) |
|
protected SpringApplication |
createSpringApplication(ResourceLoader resourceLoader, java.lang.Class<?>[] sources) |
|
GrailsAppBuilder |
environment(ConfigurableEnvironment environment) |
|
GrailsAppBuilder |
environmentPrefix(java.lang.String environmentPrefix) |
|
GrailsAppBuilder |
headless(boolean headless) |
|
GrailsAppBuilder |
initializers(ApplicationContextInitializer<?>[] initializers) |
|
GrailsAppBuilder |
lazyInitialization(boolean lazyInitialization) |
|
GrailsAppBuilder |
listeners(ApplicationListener<?>[] listeners) |
|
GrailsAppBuilder |
logStartupInfo(boolean logStartupInfo) |
|
GrailsAppBuilder |
main(java.lang.Class<?> mainApplicationClass) |
|
GrailsAppBuilder |
parent(java.lang.Class<?>[] sources)Creates a parent for this builder, or adds sources to the parent already created. |
|
GrailsAppBuilder |
parent(ConfigurableApplicationContext parentContext)Uses an application context that is already running as the parent of the context this builder creates. |
|
GrailsAppBuilder |
profiles(java.lang.String[] profiles) |
|
GrailsAppBuilder |
properties(java.lang.String[] defaultProperties) |
|
GrailsAppBuilder |
properties(java.util.Properties defaultProperties) |
|
GrailsAppBuilder |
properties(java.util.Map<java.lang.String, java.lang.Object> defaults)Adds default properties, and shares them with the parent when this builder has one, as SpringApplicationBuilder.properties does. |
|
GrailsAppBuilder |
registerShutdownHook(boolean registerShutdownHook)Sets whether the application registers a JVM shutdown hook. |
|
GrailsAppBuilder |
resourceLoader(ResourceLoader resourceLoader) |
|
ConfigurableApplicationContext |
run(java.lang.String[] args) |
|
GrailsAppBuilder |
setAddConversionService(boolean addConversionService) |
|
GrailsAppBuilder |
sibling(java.lang.Class<?>[] sources)Runs this application if it is not running yet and creates another child of its parent. |
|
GrailsAppBuilder |
sibling(java.lang.Class<?>[] sources, java.lang.String[] args)Runs this application with the given arguments if it is not running yet and creates another child of its parent. |
|
GrailsAppBuilder |
sources(java.lang.Class<?>[] sources) |
|
GrailsAppBuilder |
web(WebApplicationType webApplicationType) |
| Methods inherited from class | Name |
|---|---|
class SpringApplicationBuilder |
addBootstrapRegistryInitializer, addCommandLineProperties, allowCircularReferences, application, applicationStartup, banner, bannerMode, beanNameGenerator, build, build, child, context, contextFactory, environment, environmentPrefix, equals, getClass, hashCode, headless, initializers, lazyInitialization, listeners, logStartupInfo, main, notify, notifyAll, parent, parent, profiles, properties, properties, properties, registerShutdownHook, resourceLoader, run, setAddConversionService, sibling, sibling, sources, toString, wait, wait, wait, web |
Create a new builder for a GrailsApp that loads beans from the given sources.
sources - the bean sourcesCreate a new builder for a GrailsApp that loads beans from the given sources through the given resource loader.
resourceLoader - the resource loader to usesources - the bean sourcesBuilds the GrailsApp with the given arguments, running the parent first when this builder has one.
args - the arguments to run the parent with, if any Creates a child of this builder whose context has the context this builder creates as its
parent, as SpringApplicationBuilder.child does, except that the child is a
GrailsAppBuilder running a GrailsApp. The default properties, environment and
additional profiles configured so far are copied to the child.
As in Spring Boot, a parent cannot host an embedded web server, because the servlets could not be initialized at the right point of the child's lifecycle: this builder is switched to WebApplicationType.NONE and its banner is turned off. The Grails application class therefore belongs in the child when the application serves web requests.
sources - the sources of the child contextCreates a parent for this builder, or adds sources to the parent already created. The parent runs before this application, without a web server, and its context becomes the parent of this application's context. Returns the parent builder, as SpringApplicationBuilder.parent does; call run(String[]) on the child to start both.
sources - the sources of the parent contextUses an application context that is already running as the parent of the context this builder creates. Returns this builder, as SpringApplicationBuilder.parent does.
parentContext - the running parent contextAdds default properties, and shares them with the parent when this builder has one, as SpringApplicationBuilder.properties does.
Sets whether the application registers a JVM shutdown hook. A child registers none unless this is called, because closing its parent closes it.
Runs this application if it is not running yet and creates another child of its parent.
sources - the sources of the sibling contextRuns this application with the given arguments if it is not running yet and creates another child of its parent.
sources - the sources of the sibling contextargs - the arguments to run this application with