use of org.springframework.beans.factory.support.GenericBeanDefinition in project ignite by apache.
the class GridFactorySelfTest method getTestApplicationContext.
/**
* Gets test Spring application context with single {@link StringBuilder} bean
* with name "myBean" and value "Test string".
*
* @return Spring application context.
*/
private ApplicationContext getTestApplicationContext() {
AbstractBeanDefinition def = new GenericBeanDefinition();
def.setBeanClass(StringBuilder.class);
ConstructorArgumentValues args = new ConstructorArgumentValues();
args.addGenericArgumentValue("Test string");
def.setConstructorArgumentValues(args);
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("myBean", def);
return ctx;
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project engine by craftercms.
the class BeanDefinitionUtils method createBeanDefinitionFromOriginal.
/**
* Creates a bean definition for the specified bean name. If the parent context of the current context contains a
* bean definition with the same name, the definition is created as a bean copy of the parent definition. This
* method is useful for config parsers that want to create a bean definition from configuration but also want to
* retain the default properties of the original bean.
*
* @param applicationContext the current application context
* @param beanName
* @return the bean definition
*/
public static BeanDefinition createBeanDefinitionFromOriginal(ApplicationContext applicationContext, String beanName) {
ApplicationContext parentContext = applicationContext.getParent();
BeanDefinition parentDefinition = null;
if (parentContext != null && parentContext.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory parentBeanFactory = (ConfigurableListableBeanFactory) parentContext.getAutowireCapableBeanFactory();
try {
parentDefinition = parentBeanFactory.getBeanDefinition(beanName);
} catch (NoSuchBeanDefinitionException e) {
}
}
if (parentDefinition != null) {
return new GenericBeanDefinition(parentDefinition);
} else {
return new GenericBeanDefinition();
}
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project grails-core by grails.
the class LazyTagLibraryLookup method lookupTagLibrary.
@Override
public GroovyObject lookupTagLibrary(String namespace, String tagName) {
GroovyObject tagLibrary = super.lookupTagLibrary(namespace, tagName);
if (tagLibrary == null) {
String tagKey = tagNameKey(namespace, tagName);
GrailsTagLibClass taglibClass = lazyLoadableTagLibs.get(tagKey);
if (taglibClass != null) {
if (!applicationContext.containsBean(taglibClass.getFullName())) {
GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(taglibClass.getClazz());
bd.setAutowireCandidate(true);
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
((GenericApplicationContext) applicationContext).getDefaultListableBeanFactory().registerBeanDefinition(taglibClass.getFullName(), bd);
}
registerTagLib(taglibClass);
tagLibrary = super.lookupTagLibrary(namespace, tagName);
}
}
return tagLibrary;
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project grails-core by grails.
the class DefaultBeanConfiguration method createBeanDefinition.
protected AbstractBeanDefinition createBeanDefinition() {
AbstractBeanDefinition bd = new GenericBeanDefinition();
if (!constructorArgs.isEmpty()) {
ConstructorArgumentValues cav = new ConstructorArgumentValues();
for (Object constructorArg : constructorArgs) {
cav.addGenericArgumentValue(constructorArg);
}
bd.setConstructorArgumentValues(cav);
}
if (clazz != null) {
bd.setLazyInit(clazz.getAnnotation(Lazy.class) != null);
bd.setBeanClass(clazz);
}
bd.setScope(singleton ? AbstractBeanDefinition.SCOPE_SINGLETON : AbstractBeanDefinition.SCOPE_PROTOTYPE);
if (parentName != null) {
bd.setParentName(parentName);
}
wrapper = new BeanWrapperImpl(bd);
return bd;
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project grails-core by grails.
the class GrailsApplicationContext method registerSingleton.
/**
* Register a singleton bean with the underlying bean factory.
* <p>For more advanced needs, register with the underlying BeanFactory directly.
* @see #getDefaultListableBeanFactory
*/
public void registerSingleton(String name, Class<?> clazz, MutablePropertyValues pvs) throws BeansException {
GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(clazz);
bd.setPropertyValues(pvs);
getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
Aggregations