public class BeanBuilder
extends groovy.lang.GroovyObjectSupport
Runtime bean configuration wrapper. Like a Groovy builder, but more of a DSL for Spring configuration. Allows syntax like:
import org.hibernate.SessionFactory
import org.apache.commons.dbcp.BasicDataSource
BeanBuilder builder = new BeanBuilder()
builder.beans {
dataSource(BasicDataSource) { // <--- invokeMethod
driverClassName = "org.hsqldb.jdbcDriver"
url = "jdbc:hsqldb:mem:grailsDB"
username = "sa" // <-- setProperty
password = ""
settings = [mynew:"setting"]
}
sessionFactory(SessionFactory) {
dataSource = dataSource // <-- getProperty for retrieving refs
}
myService(MyService) {
nestedBean = { AnotherBean bean-> // <-- setProperty with closure for nested bean
dataSource = dataSource
}
}
}
You can also use the Spring IO API to load resources containing beans defined as a Groovy script using either the constructors or the loadBeans(Resource[] resources) method
| Constructor and Description |
|---|
BeanBuilder() |
BeanBuilder(org.springframework.context.ApplicationContext parent) |
BeanBuilder(org.springframework.context.ApplicationContext parent,
ClassLoader classLoader) |
BeanBuilder(ClassLoader classLoader) |
| Modifier and Type | Method and Description |
|---|---|
BeanBuilder |
beans(groovy.lang.Closure callable)
When an methods argument is only a closure it is a set of bean definitions
|
org.springframework.web.context.WebApplicationContext |
createApplicationContext() |
org.springframework.beans.factory.config.BeanDefinition |
getBeanDefinition(String name)
Retrieves a BeanDefinition for the given name
|
Map<String,org.springframework.beans.factory.config.BeanDefinition> |
getBeanDefinitions()
Retrieves all BeanDefinitions for this BeanBuilder
|
org.springframework.context.ApplicationContext |
getParentCtx()
Retrieves the parent ApplicationContext
|
Object |
getProperty(String name)
This method overrides property retrieval in the scope of the BeanBuilder to either:
a) Retrieve a variable from the bean builder's binding if it exits
b) Retrieve a RuntimeBeanReference for a specific bean if it exists
c) Otherwise just delegate to super.getProperty which will resolve properties from the BeanBuilder itself
|
hudson.util.spring.RuntimeSpringConfiguration |
getSpringConfig()
Retrieves the RuntimeSpringConfiguration instance used the the BeanBuilder
|
void |
loadBeans(org.springframework.core.io.Resource resource)
Loads a single Resource into the bean builder
|
void |
loadBeans(org.springframework.core.io.Resource[] resources)
Loads a set of given beans
|
void |
loadBeans(String resourcePattern)
Takes a resource pattern as (@see org.springframework.core.io.support.PathMatchingResourcePatternResolver)
This allows you load multiple bean resources in this single builder
eg loadBeans("classpath:*Beans.groovy")
|
Object |
methodMissing(String name,
Object arg)
This method is invoked by Groovy when a method that's not defined in Java is invoked.
|
org.springframework.beans.factory.config.RuntimeBeanReference |
parentRef(String refName) |
void |
parse(InputStream script)
Parses the bean definition groovy script.
|
void |
parse(InputStream script,
groovy.lang.Binding binding)
Parses the bean definition groovy script by first exporting the given
Binding. |
org.springframework.beans.factory.config.RuntimeBeanReference |
ref(String refName) |
org.springframework.beans.factory.config.RuntimeBeanReference |
ref(String refName,
boolean parentRef) |
void |
registerBeans(org.springframework.context.support.StaticApplicationContext ctx) |
void |
setBinding(groovy.lang.Binding b)
Sets the binding (the variables available in the scope of the BeanBuilder)
|
void |
setProperty(String name,
Object value)
This method overrides property setting in the scope of the BeanBuilder to set
properties on the current BeanConfiguration
|
void |
setSpringConfig(hudson.util.spring.RuntimeSpringConfiguration springConfig)
Sets the runtime Spring configuration instance to use.
|
public BeanBuilder()
public BeanBuilder(ClassLoader classLoader)
public BeanBuilder(org.springframework.context.ApplicationContext parent)
public BeanBuilder(org.springframework.context.ApplicationContext parent,
ClassLoader classLoader)
public void parse(InputStream script)
public void parse(InputStream script, groovy.lang.Binding binding)
Binding.public org.springframework.context.ApplicationContext getParentCtx()
public hudson.util.spring.RuntimeSpringConfiguration getSpringConfig()
public org.springframework.beans.factory.config.BeanDefinition getBeanDefinition(String name)
name - The bean definitionpublic Map<String,org.springframework.beans.factory.config.BeanDefinition> getBeanDefinitions()
public void setSpringConfig(hudson.util.spring.RuntimeSpringConfiguration springConfig)
springConfig - The spring configpublic void loadBeans(String resourcePattern) throws IOException
resourcePattern - IOException - When the path cannot be matchedpublic void loadBeans(org.springframework.core.io.Resource resource)
throws IOException
resource - The resource to loadIOException - When an error occurspublic void loadBeans(org.springframework.core.io.Resource[] resources)
throws IOException
resources - The resources to loadIOExceptionpublic void registerBeans(org.springframework.context.support.StaticApplicationContext ctx)
public org.springframework.beans.factory.config.RuntimeBeanReference ref(String refName)
public org.springframework.beans.factory.config.RuntimeBeanReference parentRef(String refName)
public org.springframework.beans.factory.config.RuntimeBeanReference ref(String refName, boolean parentRef)
public Object methodMissing(String name, Object arg)
public org.springframework.web.context.WebApplicationContext createApplicationContext()
public BeanBuilder beans(groovy.lang.Closure callable)
callable - The closure argumentpublic void setProperty(String name, Object value)
setProperty in interface groovy.lang.GroovyObjectsetProperty in class groovy.lang.GroovyObjectSupportpublic Object getProperty(String name)
getProperty in interface groovy.lang.GroovyObjectgetProperty in class groovy.lang.GroovyObjectSupportpublic void setBinding(groovy.lang.Binding b)
b - The Binding instanceCopyright © 2019. All rights reserved.