use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.
the class AbstractBeanFactoryBasedTargetSourceCreator method getTargetSource.
//---------------------------------------------------------------------
// Implementation of the TargetSourceCreator interface
//---------------------------------------------------------------------
@Override
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
AbstractBeanFactoryBasedTargetSource targetSource = createBeanFactoryBasedTargetSource(beanClass, beanName);
if (targetSource == null) {
return null;
}
if (logger.isDebugEnabled()) {
logger.debug("Configuring AbstractBeanFactoryBasedTargetSource: " + targetSource);
}
DefaultListableBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);
// We need to override just this bean definition, as it may reference other beans
// and we're happy to take the parent's definition for those.
// Always use prototype scope if demanded.
BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
if (isPrototypeBased()) {
bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
}
internalBeanFactory.registerBeanDefinition(beanName, bdCopy);
// Complete configuring the PrototypeTargetSource.
targetSource.setTargetBeanName(beanName);
targetSource.setBeanFactory(internalBeanFactory);
return targetSource;
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.
the class ScriptFactoryPostProcessor method createScriptFactoryBeanDefinition.
/**
* Create a ScriptFactory bean definition based on the given script definition,
* extracting only the definition data that is relevant for the ScriptFactory
* (that is, only bean class and constructor arguments).
* @param bd the full script bean definition
* @return the extracted ScriptFactory bean definition
* @see org.springframework.scripting.ScriptFactory
*/
protected BeanDefinition createScriptFactoryBeanDefinition(BeanDefinition bd) {
GenericBeanDefinition scriptBd = new GenericBeanDefinition();
scriptBd.setBeanClassName(bd.getBeanClassName());
scriptBd.getConstructorArgumentValues().addArgumentValues(bd.getConstructorArgumentValues());
return scriptBd;
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-boot by spring-projects.
the class ServletComponentScanRegistrar method addPostProcessor.
private void addPostProcessor(BeanDefinitionRegistry registry, Set<String> packagesToScan) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(ServletComponentRegisteringPostProcessor.class);
beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(packagesToScan);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN_NAME, beanDefinition);
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.
the class GroovyBeanDefinitionWrapper method createBeanDefinition.
protected AbstractBeanDefinition createBeanDefinition() {
AbstractBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(this.clazz);
if (!CollectionUtils.isEmpty(this.constructorArgs)) {
ConstructorArgumentValues cav = new ConstructorArgumentValues();
for (Object constructorArg : this.constructorArgs) {
cav.addGenericArgumentValue(constructorArg);
}
bd.setConstructorArgumentValues(cav);
}
if (this.parentName != null) {
bd.setParentName(this.parentName);
}
this.definitionWrapper = new BeanWrapperImpl(bd);
return bd;
}
use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testIncompleteBeanDefinition.
@Test
public void testIncompleteBeanDefinition() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("testBean", new GenericBeanDefinition());
try {
bf.getBean("testBean");
fail("Should have thrown BeanCreationException");
} catch (BeanCreationException ex) {
assertTrue(ex.getRootCause() instanceof IllegalStateException);
}
}
Aggregations