This bean definition reader also understands XML bean definition files, allowing for seamless mixing and matching with Groovy bean definition files.
Typically applied to a
org.
or a org.,
but can be used against any BeanDefinitionRegistry implementation.
import org.hibernate.SessionFactory
import org.apache.commons.dbcp.BasicDataSource
def reader = new GroovyBeanDefinitionReader(myApplicationContext)
reader.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 references
}
myService(MyService) {
nestedBean = { AnotherBean bean -> // <-- setProperty with closure for nested bean
dataSource = dataSource
}
}
}
You can also load resources containing beans defined in a Groovy script using
either the loadBeanDefinitions(Resource. or
loadBeanDefinitions(String. method, with a script looking similar to
the following.
import org.hibernate.SessionFactory
import org.apache.commons.dbcp.BasicDataSource
beans {
dataSource(BasicDataSource) {
driverClassName = "org.hsqldb.jdbcDriver"
url = "jdbc:hsqldb:mem:grailsDB"
username = "sa"
password = ""
settings = [mynew:"setting"]
}
sessionFactory(SessionFactory) {
dataSource = dataSource
}
myService(MyService) {
nestedBean = { AnotherBean bean ->
dataSource = dataSource
}
}
}
BeanDefinitionRegistry, org.springframework.beans.factory.support.DefaultListableBeanFactory , org.springframework.context.support.GenericApplicationContext , org.springframework.context.support.GenericGroovyApplicationContext
| Modifier and Type | Class and Description |
|---|---|
| private static class | GroovyBeanDefinitionReader.
This class is used to defer the adding of a property to a bean definition until later. |
| private class | GroovyBeanDefinitionReader.
A RuntimeBeanReference that takes care of adding new properties to runtime references. |
| Modifier and Type | Field and Description |
|---|---|
| private Binding | |
| private GroovyBeanDefinitionWrapper | |
| private final Map | |
| private final XmlBeanDefinitionReader | groovyDslXmlBeanDefinitionReader
Groovy DSL |
| private MetaClass | |
| private final Map | |
| private final XmlBeanDefinitionReader | standardXmlBeanDefinitionReader
Standard |
| Access | Constructor and Description |
|---|---|
| public | GroovyBeanDefinitionReader(BeanDefinitionRegistry
the registry)BeanDefinitionRegistry to load bean definitions intoCreate a new |
| public | GroovyBeanDefinitionReader(XmlBeanDefinitionReader
the xmlBeanDefinitionReader)XmlBeanDefinitionReader to
derive the registry from and to delegate Groovy DSL loading toCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| protected void | |
| public GenericBeanDefinition | |
| public AbstractBeanDefinition | |
| public GroovyBeanDefinitionReader | |
| private GroovyDynamicElementReader | |
| private void | |
| public Binding | |
| public MetaClass | getMetaClass()
Implements groovy. Returns the metaclass for a given class. |
| public Object | getProperty(String
the name of the property of interest name)Overrides default groovy. This method overrides property retrieval in the scope of the
|
| public void | importBeans(String
the resource pattern resourcePattern)Import Spring bean definitions from either XML or Groovy sources into the current bean builder instance. |
| protected GroovyBeanDefinitionReader | Returns: thisGroovyBeanDefinitionReader instancethe closure argument callable)When a method argument is only a closure it is a set of bean definitions. |
| private GroovyBeanDefinitionWrapper | Returns: the bean definition wrapperthe name of the bean to define beanName, Object[] the arguments to the bean. The first argument is the class name, the last
argument is sometimes a closure. All the arguments in between are constructor arguments. args)This method is called when a bean definition node is called. |
| public Object | invokeMethod(String
the name of the method to call name, Object the arguments to use for the method call arg)Overrides default groovy. This method overrides method invocation to create beans for each method name that takes a class argument. |
| public int | Returns: the number of bean definitions foundthe resource descriptor for the Groovy script or XML file resource)Implements org. Load bean definitions from the specified Groovy script or XML file. |
| public int | Returns: the number of bean definitions foundthe resource descriptor for the Groovy script or XML file,
allowing specification of an encoding to use for parsing the file encodedResource)Load bean definitions from the specified Groovy script or XML file. |
| private Object | Returns: either the original list or a managed copy of itthe original List list)Checks whether there are any |
| private Object | Returns: either the original map or a managed copy of itthe original Map map)Checks whether there are any |
| protected List | |
| public void | setBinding(Binding binding)
Set the binding, i.e. the Groovy variables available in the scope
of a |
| public void | setMetaClass(MetaClass
the new metaclass metaClass)Implements groovy. Allows the MetaClass to be replaced with a derived implementation. |
| public void | setProperty(String
the name of the property of interest name, Object the new value for the property value)Overrides default groovy. This method overrides property setting in the scope of the |
| public void |
| binding | back to summary |
|---|---|
| private Binding binding
| |
| currentBeanDefinition | back to summary |
|---|---|
| private GroovyBeanDefinitionWrapper currentBeanDefinition
| |
| deferredProperties | back to summary |
|---|---|
| private final Map<String, GroovyBeanDefinitionReader. | |
| groovyDslXmlBeanDefinitionReader | back to summary |
|---|---|
| private final XmlBeanDefinitionReader groovyDslXmlBeanDefinitionReader Groovy DSL | |
| metaClass | back to summary |
|---|---|
| private MetaClass metaClass | |
| namespaces | back to summary |
|---|---|
| private final Map<String, String> namespaces | |
| standardXmlBeanDefinitionReader | back to summary |
|---|---|
| private final XmlBeanDefinitionReader standardXmlBeanDefinitionReader Standard | |
| GroovyBeanDefinitionReader | back to summary |
|---|---|
| public GroovyBeanDefinitionReader(BeanDefinitionRegistry registry) Create a new
| |
| GroovyBeanDefinitionReader | back to summary |
|---|---|
| public GroovyBeanDefinitionReader(XmlBeanDefinitionReader xmlBeanDefinitionReader) Create a new The supplied
| |
| addDeferredProperty | back to summary |
|---|---|
| private boolean addDeferredProperty(String property, Object newValue) | |
| applyPropertyToBeanDefinition | back to summary |
|---|---|
| protected void applyPropertyToBeanDefinition(String name, Object value) | |
| bean | back to summary |
|---|---|
| public GenericBeanDefinition bean(Class<?> type) Define an inner bean definition.
| |
| bean | back to summary |
|---|---|
| public AbstractBeanDefinition bean(Class<?> type, Object... args) Define an inner bean definition.
| |
| beans | back to summary |
|---|---|
| public GroovyBeanDefinitionReader beans(Closure<?> closure) Defines a set of beans for the given block or closure.
| |
| createDynamicElementReader | back to summary |
|---|---|
| private GroovyDynamicElementReader createDynamicElementReader(String namespace) | |
| finalizeDeferredProperties | back to summary |
|---|---|
| private void finalizeDeferredProperties() | |
| getBinding | back to summary |
|---|---|
| public Binding getBinding() Return a specified binding for Groovy variables, if any.
| |
| getMetaClass | back to summary |
|---|---|
| public MetaClass getMetaClass() Implements groovy. Doc from groovy. Returns the metaclass for a given class. | |
| getProperty | back to summary |
|---|---|
| public Object getProperty(String name) Overrides default groovy. This method overrides property retrieval in the scope of the
| |
| importBeans | back to summary |
|---|---|
| public void importBeans(String resourcePattern) throws IOException Import Spring bean definitions from either XML or Groovy sources into the current bean builder instance.
| |
| invokeBeanDefiningClosure | back to summary |
|---|---|
| protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure<?> callable) When a method argument is only a closure it is a set of bean definitions.
| |
| invokeBeanDefiningMethod | back to summary |
|---|---|
| private GroovyBeanDefinitionWrapper invokeBeanDefiningMethod(String beanName, Object[] args) This method is called when a bean definition node is called.
| |
| invokeMethod | back to summary |
|---|---|
| public Object invokeMethod(String name, Object arg) Overrides default groovy. This method overrides method invocation to create beans for each method name that takes a class argument.
| |
| loadBeanDefinitions | back to summary |
|---|---|
| public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException Implements org. Load bean definitions from the specified Groovy script or XML file. Note that
| |
| loadBeanDefinitions | back to summary |
|---|---|
| public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException Load bean definitions from the specified Groovy script or XML file. Note that
| |
| manageListIfNecessary | back to summary |
|---|---|
| private Object manageListIfNecessary(List<?> list) Checks whether there are any | |
| manageMapIfNecessary | back to summary |
|---|---|
| private Object manageMapIfNecessary(Map<?, ?> map) Checks whether there are any | |
| resolveConstructorArguments | back to summary |
|---|---|
| protected List | |
| setBinding | back to summary |
|---|---|
| public void setBinding(Binding binding) Set the binding, i.e. the Groovy variables available in the scope
of a | |
| setMetaClass | back to summary |
|---|---|
| public void setMetaClass(MetaClass metaClass) Implements groovy. Doc from groovy. Allows the MetaClass to be replaced with a derived implementation. | |
| setProperty | back to summary |
|---|---|
| public void setProperty(String name, Object value) Overrides default groovy. This method overrides property setting in the scope of the
| |
| xmlns | back to summary |
|---|---|
| public void xmlns(Map<String, String> definition) Define a Spring XML namespace definition to use. | |
| Modifier and Type | Field and Description |
|---|---|
| private final GroovyBeanDefinitionWrapper | |
| private final String | |
| public Object |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| beanDefinition | back to summary |
|---|---|
| private final GroovyBeanDefinitionWrapper beanDefinition | |
| name | back to summary |
|---|---|
| private final String name | |
| value | back to summary |
|---|---|
| public Object value | |
| DeferredProperty | back to summary |
|---|---|
| public DeferredProperty(GroovyBeanDefinitionWrapper beanDefinition, String name, Object value) | |
| apply | back to summary |
|---|---|
| public void apply() | |
| Modifier and Type | Class and Description |
|---|---|
| private class | GroovyBeanDefinitionReader.
Wraps a bean definition property and ensures that any RuntimeBeanReference additions to it are deferred for resolution later. |
| Modifier and Type | Field and Description |
|---|---|
| private final GroovyBeanDefinitionWrapper | |
| private MetaClass |
| Access | Constructor and Description |
|---|---|
| public | GroovyRuntimeBeanReference(String beanName, GroovyBeanDefinitionWrapper beanDefinition, boolean toParent)
|
| Modifier and Type | Method and Description |
|---|---|
| public MetaClass | getMetaClass()
Implements groovy. Returns the metaclass for a given class. |
| public Object | getProperty(String
the name of the property of interest property)Overrides default groovy. Retrieves a property value. |
| public Object | invokeMethod(String
the name of the method to call name, Object the arguments to use for the method call args)Overrides default groovy. Invokes the given method. |
| public void | setMetaClass(MetaClass
the new metaclass metaClass)Implements groovy. Allows the MetaClass to be replaced with a derived implementation. |
| public void | setProperty(String
the name of the property of interest property, Object the new value for the property newValue)Overrides default groovy. Sets the given property to the new value. |
| beanDefinition | back to summary |
|---|---|
| private final GroovyBeanDefinitionWrapper beanDefinition | |
| metaClass | back to summary |
|---|---|
| private MetaClass metaClass | |
| GroovyRuntimeBeanReference | back to summary |
|---|---|
| public GroovyRuntimeBeanReference(String beanName, GroovyBeanDefinitionWrapper beanDefinition, boolean toParent) | |
| getMetaClass | back to summary |
|---|---|
| public MetaClass getMetaClass() Implements groovy. Doc from groovy. Returns the metaclass for a given class. | |
| getProperty | back to summary |
|---|---|
| public Object getProperty(String property) Overrides default groovy. Doc from groovy. Retrieves a property value. | |
| invokeMethod | back to summary |
|---|---|
| public Object invokeMethod(String name, Object args) Overrides default groovy. Doc from groovy. Invokes the given method. | |
| setMetaClass | back to summary |
|---|---|
| public void setMetaClass(MetaClass metaClass) Implements groovy. Doc from groovy. Allows the MetaClass to be replaced with a derived implementation. | |
| setProperty | back to summary |
|---|---|
| public void setProperty(String property, Object newValue) Overrides default groovy. Doc from groovy. Sets the given property to the new value. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | |
| public Object | getProperty(String
the name of the property of interest name)Overrides default groovy. Retrieves a property value. |
| public Object | invokeMethod(String
the name of the method to call name, Object the arguments to use for the method call args)Overrides default groovy. Invokes the given method. |
| public void | |
| public void | setProperty(String
the name of the property of interest name, Object the new value for the property value)Overrides default groovy. Sets the given property to the new value. |
| private void |
| propertyName | back to summary |
|---|---|
| private final String propertyName | |
| propertyValue | back to summary |
|---|---|
| private final Object propertyValue | |
| GroovyPropertyValue | back to summary |
|---|---|
| public GroovyPropertyValue(String propertyName, Object propertyValue) | |
| add | back to summary |
|---|---|
public boolean add(Object value)
| |
| addAll | back to summary |
|---|---|
public boolean addAll(Collection<?> values)
| |
| getProperty | back to summary |
|---|---|
| public Object getProperty(String name) Overrides default groovy. Doc from groovy. Retrieves a property value. | |
| invokeMethod | back to summary |
|---|---|
| public Object invokeMethod(String name, Object args) Overrides default groovy. Doc from groovy. Invokes the given method. | |
| leftShift | back to summary |
|---|---|
public void leftShift(Object value)
| |
| setProperty | back to summary |
|---|---|
| public void setProperty(String name, Object value) Overrides default groovy. Doc from groovy. Sets the given property to the new value. | |
| updateDeferredProperties | back to summary |
|---|---|
| private void updateDeferredProperties(Object value) | |