Search in sources :

Example 31 with GenericBeanDefinition

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

the class InjectAnnotationBeanPostProcessorTests 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");
    } catch (BeanCreationException ex) {
        assertTrue(ex.getRootCause() instanceof IllegalStateException);
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanCreationException(org.springframework.beans.factory.BeanCreationException) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 32 with GenericBeanDefinition

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

the class EntityScanPackages method register.

/**
	 * Register the specified entity scan packages with the system.
	 * @param registry the source registry
	 * @param packageNames the package names to register
	 */
public static void register(BeanDefinitionRegistry registry, Collection<String> packageNames) {
    Assert.notNull(registry, "Registry must not be null");
    Assert.notNull(packageNames, "PackageNames must not be null");
    if (registry.containsBeanDefinition(BEAN)) {
        BeanDefinition beanDefinition = registry.getBeanDefinition(BEAN);
        ConstructorArgumentValues constructorArguments = beanDefinition.getConstructorArgumentValues();
        constructorArguments.addIndexedArgumentValue(0, addPackageNames(constructorArguments, packageNames));
    } else {
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(EntityScanPackages.class);
        beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, packageNames.toArray(new String[packageNames.size()]));
        beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        registry.registerBeanDefinition(BEAN, beanDefinition);
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 33 with GenericBeanDefinition

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

the class JaxWsSupportTests method doTestJaxWsPortAccess.

private void doTestJaxWsPortAccess(WebServiceFeature... features) throws Exception {
    GenericApplicationContext ac = new GenericApplicationContext();
    GenericBeanDefinition serviceDef = new GenericBeanDefinition();
    serviceDef.setBeanClass(OrderServiceImpl.class);
    ac.registerBeanDefinition("service", serviceDef);
    GenericBeanDefinition exporterDef = new GenericBeanDefinition();
    exporterDef.setBeanClass(SimpleJaxWsServiceExporter.class);
    exporterDef.getPropertyValues().add("baseAddress", "http://localhost:9999/");
    ac.registerBeanDefinition("exporter", exporterDef);
    GenericBeanDefinition clientDef = new GenericBeanDefinition();
    clientDef.setBeanClass(JaxWsPortProxyFactoryBean.class);
    clientDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
    clientDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
    clientDef.getPropertyValues().add("username", "juergen");
    clientDef.getPropertyValues().add("password", "hoeller");
    clientDef.getPropertyValues().add("serviceName", "OrderService");
    clientDef.getPropertyValues().add("serviceInterface", OrderService.class);
    clientDef.getPropertyValues().add("lookupServiceOnStartup", Boolean.FALSE);
    if (features != null) {
        clientDef.getPropertyValues().add("portFeatures", features);
    }
    ac.registerBeanDefinition("client", clientDef);
    GenericBeanDefinition serviceFactoryDef = new GenericBeanDefinition();
    serviceFactoryDef.setBeanClass(LocalJaxWsServiceFactoryBean.class);
    serviceFactoryDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
    serviceFactoryDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
    serviceFactoryDef.getPropertyValues().add("serviceName", "OrderService");
    ac.registerBeanDefinition("orderService", serviceFactoryDef);
    ac.registerBeanDefinition("accessor", new RootBeanDefinition(ServiceAccessor.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
    try {
        ac.refresh();
        OrderService orderService = ac.getBean("client", OrderService.class);
        assertTrue(orderService instanceof BindingProvider);
        ((BindingProvider) orderService).getRequestContext();
        String order = orderService.getOrder(1000);
        assertEquals("order 1000", order);
        try {
            orderService.getOrder(0);
            fail("Should have thrown OrderNotFoundException");
        } catch (OrderNotFoundException ex) {
        // expected
        } catch (RemoteAccessException ex) {
        // ignore - probably setup issue with JAX-WS provider vs JAXB
        }
        ServiceAccessor serviceAccessor = ac.getBean("accessor", ServiceAccessor.class);
        order = serviceAccessor.orderService.getOrder(1000);
        assertEquals("order 1000", order);
        try {
            serviceAccessor.orderService.getOrder(0);
            fail("Should have thrown OrderNotFoundException");
        } catch (OrderNotFoundException ex) {
        // expected
        } catch (WebServiceException ex) {
        // ignore - probably setup issue with JAX-WS provider vs JAXB
        }
    } catch (BeanCreationException ex) {
        if ("exporter".equals(ex.getBeanName()) && ex.getRootCause() instanceof ClassNotFoundException) {
        // ignore - probably running on JDK without the JAX-WS impl present
        } else {
            throw ex;
        }
    } finally {
        ac.close();
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanCreationException(org.springframework.beans.factory.BeanCreationException) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) WebServiceException(javax.xml.ws.WebServiceException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BindingProvider(javax.xml.ws.BindingProvider)

Example 34 with GenericBeanDefinition

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

the class StaticApplicationContext method registerPrototype.

/**
	 * Register a prototype bean with the underlying bean factory.
	 * <p>For more advanced needs, register with the underlying BeanFactory directly.
	 * @see #getDefaultListableBeanFactory
	 */
public void registerPrototype(String name, Class<?> clazz) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
    bd.setBeanClass(clazz);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Example 35 with GenericBeanDefinition

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

the class StaticApplicationContext method registerPrototype.

/**
	 * Register a prototype bean with the underlying bean factory.
	 * <p>For more advanced needs, register with the underlying BeanFactory directly.
	 * @see #getDefaultListableBeanFactory
	 */
public void registerPrototype(String name, Class<?> clazz, MutablePropertyValues pvs) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setScope(GenericBeanDefinition.SCOPE_PROTOTYPE);
    bd.setBeanClass(clazz);
    bd.setPropertyValues(pvs);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Aggregations

GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)39 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 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 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