Package org.grails.spring
Class DefaultRuntimeSpringConfiguration
java.lang.Object
org.grails.spring.DefaultRuntimeSpringConfiguration
- All Implemented Interfaces:
RuntimeSpringConfiguration
A programmable runtime Spring configuration that allows a spring ApplicationContext
to be constructed at runtime.
Credit must go to Solomon Duskis and the
article: http://jroller.com/page/Solomon?entry=programmatic_configuration_in_spring
- Since:
- 0.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.beans.factory.ListableBeanFactoryprotected ClassLoaderprotected org.springframework.context.support.GenericApplicationContextprotected org.springframework.context.ApplicationContext -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent) DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent, ClassLoader cl) -
Method Summary
Modifier and TypeMethodDescriptionaddAbstractBean(String name) \ Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object.voidAdds an alias to a given bean name.voidaddBeanConfiguration(String beanName, BeanConfiguration beanConfiguration) Adds a bean configuration to the list of beans to be created.voidaddBeanDefinition(String name, org.springframework.beans.factory.config.BeanDefinition bd) Adds a Spring BeanDefinition.addPrototypeBean(String name) Adds an empty prototype bean configuration.addPrototypeBean(String name, Class clazz) Adds a prototype bean definition.addSingletonBean(String name) Adds an empty singleton bean configuration.addSingletonBean(String name, Class clazz) Adds a singleton bean definition.addSingletonBean(String name, Class clazz, Collection args) Creates a new singleton bean and adds it to the list of bean references.booleancontainsBean(String name) Returns whether the runtime spring config contains the specified bean.protected org.springframework.context.support.GenericApplicationContextcreateApplicationContext(org.springframework.context.ApplicationContext parentCtx) Creates the ApplicationContext instance.org.springframework.beans.factory.support.AbstractBeanDefinitioncreateBeanDefinition(String name) Creates and returns the BeanDefinition that is regsitered within the given name or returns null.createPrototypeBean(String name) Creates a new prototype bean configuration.createSingletonBean(Class clazz) Creates a singleton bean configuration.createSingletonBean(Class clazz, Collection constructorArguments) Creates a singleton bean configuration.createSingletonBean(String name) Creates a new singleton bean configuration.org.springframework.context.ApplicationContextRetrieves the application context from the current state.getBeanConfig(String name) Returns the BeanConfiguration for the specified name.org.springframework.beans.factory.config.BeanDefinitiongetBeanDefinition(String beanName) Obtains a BeanDefinition instance for the given beanName.org.springframework.context.ApplicationContextprotected voidInitialises the ApplicationContext instance.voidregisterBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig) Registers the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration.voidregisterBeansWithContext(org.springframework.context.support.GenericApplicationContext applicationContext) Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext.voidregisterBeansWithRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) Registers the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry.voidregisterPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor processor) Registers a bean factory post processor with the context.voidsetBeanFactory(org.springframework.beans.factory.ListableBeanFactory beanFactory) Sets the BeanFactory implementation to use.
-
Field Details
-
context
protected org.springframework.context.support.GenericApplicationContext context -
parent
protected org.springframework.context.ApplicationContext parent -
classLoader
-
aliases
-
beanFactory
protected org.springframework.beans.factory.ListableBeanFactory beanFactory
-
-
Constructor Details
-
DefaultRuntimeSpringConfiguration
public DefaultRuntimeSpringConfiguration() -
DefaultRuntimeSpringConfiguration
public DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent) -
DefaultRuntimeSpringConfiguration
public DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent, ClassLoader cl)
-
-
Method Details
-
createApplicationContext
protected org.springframework.context.support.GenericApplicationContext createApplicationContext(org.springframework.context.ApplicationContext parentCtx) Creates the ApplicationContext instance. Subclasses can override to customise the used ApplicationContext- Parameters:
parentCtx- The parent ApplicationContext instance. Can be null.- Returns:
- An instance of GenericApplicationContext
-
initialiseApplicationContext
protected void initialiseApplicationContext()Initialises the ApplicationContext instance. -
addSingletonBean
Description copied from interface:RuntimeSpringConfigurationAdds a singleton bean definition.- Specified by:
addSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanclazz- The class of the bean- Returns:
- A BeanConfiguration instance
-
addPrototypeBean
Description copied from interface:RuntimeSpringConfigurationAdds a prototype bean definition.- Specified by:
addPrototypeBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanclazz- The class of the bean- Returns:
- A BeanConfiguration instance
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()Description copied from interface:RuntimeSpringConfigurationRetrieves the application context from the current state.- Specified by:
getApplicationContextin interfaceRuntimeSpringConfiguration- Returns:
- The ApplicationContext instance
-
getUnrefreshedApplicationContext
public org.springframework.context.ApplicationContext getUnrefreshedApplicationContext()- Specified by:
getUnrefreshedApplicationContextin interfaceRuntimeSpringConfiguration
-
addSingletonBean
Description copied from interface:RuntimeSpringConfigurationAdds an empty singleton bean configuration.- Specified by:
addSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the singleton bean- Returns:
- A BeanConfiguration instance
-
createSingletonBean
Description copied from interface:RuntimeSpringConfigurationCreates a singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references. Hence should be used for creating nested beans.- Specified by:
createSingletonBeanin interfaceRuntimeSpringConfiguration- Returns:
- A BeanConfiguration instance
-
addSingletonBean
Description copied from interface:RuntimeSpringConfigurationCreates a new singleton bean and adds it to the list of bean references.- Specified by:
addSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanclazz- The class of the beanargs- The constructor arguments of the bean- Returns:
- A BeanConfiguration instance
-
addPrototypeBean
Description copied from interface:RuntimeSpringConfigurationAdds an empty prototype bean configuration.- Specified by:
addPrototypeBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the prototype bean- Returns:
- A BeanConfiguration instance
-
createSingletonBean
Description copied from interface:RuntimeSpringConfigurationCreates a singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references. Hence should be used for creating nested beans- Specified by:
createSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
clazz- The bean classconstructorArguments- The constructor arguments- Returns:
- A BeanConfiguration instance
-
createPrototypeBean
Description copied from interface:RuntimeSpringConfigurationCreates a new prototype bean configuration. Differs from addPrototypeBean in that it doesn't add the bean to the list of bean references to be created via the getApplicationContext() method, hence can be used for creating nested beans- Specified by:
createPrototypeBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The bean name- Returns:
- A BeanConfiguration instance
-
createSingletonBean
Description copied from interface:RuntimeSpringConfigurationCreates a new singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references to be created via the getApplicationContext() method, hence can be used for creating nested beans- Specified by:
createSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The bean name- Returns:
- A BeanConfiguration instance
-
addBeanConfiguration
Description copied from interface:RuntimeSpringConfigurationAdds a bean configuration to the list of beans to be created.- Specified by:
addBeanConfigurationin interfaceRuntimeSpringConfiguration- Parameters:
beanName- The name of the bean in the contextbeanConfiguration- The BeanConfiguration instance
-
addBeanDefinition
public void addBeanDefinition(String name, org.springframework.beans.factory.config.BeanDefinition bd) Description copied from interface:RuntimeSpringConfigurationAdds a Spring BeanDefinition. Differs from BeanConfiguration which is a factory class for creating BeanDefinition instances- Specified by:
addBeanDefinitionin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanbd- The BeanDefinition instance
-
containsBean
Description copied from interface:RuntimeSpringConfigurationReturns whether the runtime spring config contains the specified bean.- Specified by:
containsBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The bean name- Returns:
- true if it does
-
getBeanConfig
Description copied from interface:RuntimeSpringConfigurationReturns the BeanConfiguration for the specified name.- Specified by:
getBeanConfigin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the bean configuration- Returns:
- The BeanConfiguration
-
createBeanDefinition
public org.springframework.beans.factory.support.AbstractBeanDefinition createBeanDefinition(String name) Description copied from interface:RuntimeSpringConfigurationCreates and returns the BeanDefinition that is regsitered within the given name or returns null.- Specified by:
createBeanDefinitionin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the bean definition- Returns:
- A BeanDefinition
-
registerPostProcessor
public void registerPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor processor) Description copied from interface:RuntimeSpringConfigurationRegisters a bean factory post processor with the context.- Specified by:
registerPostProcessorin interfaceRuntimeSpringConfiguration- Parameters:
processor- The BeanFactoryPostProcessor instance
-
getBeanNames
- Specified by:
getBeanNamesin interfaceRuntimeSpringConfiguration
-
registerBeansWithContext
public void registerBeansWithContext(org.springframework.context.support.GenericApplicationContext applicationContext) Description copied from interface:RuntimeSpringConfigurationRegisters the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext.- Specified by:
registerBeansWithContextin interfaceRuntimeSpringConfiguration- Parameters:
applicationContext- The ApplicationContext instance
-
registerBeansWithRegistry
public void registerBeansWithRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) Description copied from interface:RuntimeSpringConfigurationRegisters the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry.- Specified by:
registerBeansWithRegistryin interfaceRuntimeSpringConfiguration- Parameters:
registry- The BeanDefinitionRegistry instance
-
registerBeansWithConfig
Description copied from interface:RuntimeSpringConfigurationRegisters the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration.- Specified by:
registerBeansWithConfigin interfaceRuntimeSpringConfiguration- Parameters:
targetSpringConfig- The RuntimeSpringConfiguration instance
-
addAbstractBean
Description copied from interface:RuntimeSpringConfiguration\ Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object.- Specified by:
addAbstractBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the bean- Returns:
- The BeanConfiguration object
-
addAlias
Description copied from interface:RuntimeSpringConfigurationAdds an alias to a given bean name.- Specified by:
addAliasin interfaceRuntimeSpringConfiguration- Parameters:
alias- The aliasbeanName- The bean
-
getBeanDefinition
Description copied from interface:RuntimeSpringConfigurationObtains a BeanDefinition instance for the given beanName.- Specified by:
getBeanDefinitionin interfaceRuntimeSpringConfiguration- Parameters:
beanName- The beanName- Returns:
- The BeanDefinition or null if it doesn't exit
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.ListableBeanFactory beanFactory) Description copied from interface:RuntimeSpringConfigurationSets the BeanFactory implementation to use.- Specified by:
setBeanFactoryin interfaceRuntimeSpringConfiguration- Parameters:
beanFactory- The BeanFactory implementation
-