Search in sources :

Example 36 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.

the class ScriptFactoryPostProcessor method createScriptedObjectBeanDefinition.

/**
	 * Create a bean definition for the scripted object, based on the given script
	 * definition, extracting the definition data that is relevant for the scripted
	 * object (that is, everything but bean class and constructor arguments).
	 * @param bd the full script bean definition
	 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
	 * @param scriptSource the ScriptSource for the scripted bean
	 * @param interfaces the interfaces that the scripted bean is supposed to implement
	 * @return the extracted ScriptFactory bean definition
	 * @see org.springframework.scripting.ScriptFactory#getScriptedObject
	 */
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName, ScriptSource scriptSource, Class<?>[] interfaces) {
    GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
    objectBd.setFactoryBeanName(scriptFactoryBeanName);
    objectBd.setFactoryMethodName("getScriptedObject");
    objectBd.getConstructorArgumentValues().clear();
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
    objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
    return objectBd;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Example 37 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.

the class ApplicationContextExpressionTests method stringConcatenationWithDebugLogging.

@Test
public void stringConcatenationWithDebugLogging() {
    GenericApplicationContext ac = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(String.class);
    bd.getConstructorArgumentValues().addGenericArgumentValue("test-#{ T(java.lang.System).currentTimeMillis() }");
    ac.registerBeanDefinition("str", bd);
    ac.refresh();
    String str = ac.getBean("str", String.class);
    assertTrue(str.startsWith("test-"));
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Test(org.junit.Test)

Aggregations

GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)37 Test (org.junit.Test)10 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)7 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)7 BeanCreationException (org.springframework.beans.factory.BeanCreationException)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)3 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)2 AutowireCandidateQualifier (org.springframework.beans.factory.support.AutowireCandidateQualifier)2 ManagedList (org.springframework.beans.factory.support.ManagedList)2 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)2 Element (org.w3c.dom.Element)2 CBORFactory (com.fasterxml.jackson.dataformat.cbor.CBORFactory)1 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)1 GrailsTagLibClass (grails.core.GrailsTagLibClass)1