org.springframework.beans.factory.wiring.BeanWiringInfo Java Examples

The following examples show how to use org.springframework.beans.factory.wiring.BeanWiringInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationBeanWiringInfoResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Build the BeanWiringInfo for the given Configurable annotation.
 * @param beanInstance the bean instance
 * @param annotation the Configurable annotation found on the bean class
 * @return the resolved BeanWiringInfo
 */
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
	if (!Autowire.NO.equals(annotation.autowire())) {
		return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
	}
	else {
		if (!"".equals(annotation.value())) {
			// explicitly specified bean name
			return new BeanWiringInfo(annotation.value(), false);
		}
		else {
			// default bean name
			return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
		}
	}
}
 
Example #2
Source File: AnnotationBeanWiringInfoResolver.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * Build the BeanWiringInfo for the given Configurable annotation.
 * @param beanInstance the bean instance
 * @param annotation the Configurable annotation found on the bean class
 * @return the resolved BeanWiringInfo
 */
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
	if (!Autowire.NO.equals(annotation.autowire())) {
		return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
	}
	else {
		if (!"".equals(annotation.value())) {
			// explicitly specified bean name
			return new BeanWiringInfo(annotation.value(), false);
		}
		else {
			// default bean name
			return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
		}
	}
}
 
Example #3
Source File: AnnotationBeanWiringInfoResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build the BeanWiringInfo for the given Configurable annotation.
 * @param beanInstance the bean instance
 * @param annotation the Configurable annotation found on the bean class
 * @return the resolved BeanWiringInfo
 */
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
	if (!Autowire.NO.equals(annotation.autowire())) {
		return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
	}
	else {
		if (!"".equals(annotation.value())) {
			// explicitly specified bean name
			return new BeanWiringInfo(annotation.value(), false);
		}
		else {
			// default bean name
			return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
		}
	}
}
 
Example #4
Source File: AnnotationBeanWiringInfoResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Build the {@link BeanWiringInfo} for the given {@link Configurable} annotation.
 * @param beanInstance the bean instance
 * @param annotation the Configurable annotation found on the bean class
 * @return the resolved BeanWiringInfo
 */
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
	if (!Autowire.NO.equals(annotation.autowire())) {
		// Autowiring by name or by type
		return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
	}
	else if (!"".equals(annotation.value())) {
		// Explicitly specified bean name for bean definition to take property values from
		return new BeanWiringInfo(annotation.value(), false);
	}
	else {
		// Default bean name for bean definition to take property values from
		return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
	}
}
 
Example #5
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap());
	assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
	assertFalse(info.indicatesAutowiring());
	assertEquals("DerBigStick", info.getBeanName());
}
 
Example #6
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap());
	assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
	assertFalse(info.indicatesAutowiring());
	assertEquals(WirelessSoap.class.getName(), info.getBeanName());
}
 
Example #7
Source File: AnnotationBeanWiringInfoResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap());
	assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
	assertFalse(info.indicatesAutowiring());
	assertEquals("DerBigStick", info.getBeanName());
}
 
Example #8
Source File: AnnotationBeanWiringInfoResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap());
	assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
	assertFalse(info.indicatesAutowiring());
	assertEquals(WirelessSoap.class.getName(), info.getBeanName());
}
 
Example #9
Source File: AnnotationBeanWiringInfoResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Build the {@link BeanWiringInfo} for the given {@link Configurable} annotation.
 * @param beanInstance the bean instance
 * @param annotation the Configurable annotation found on the bean class
 * @return the resolved BeanWiringInfo
 */
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
	if (!Autowire.NO.equals(annotation.autowire())) {
		// Autowiring by name or by type
		return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
	}
	else if (!"".equals(annotation.value())) {
		// Explicitly specified bean name for bean definition to take property values from
		return new BeanWiringInfo(annotation.value(), false);
	}
	else {
		// Default bean name for bean definition to take property values from
		return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
	}
}
 
Example #10
Source File: AnnotationBeanWiringInfoResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
	Assert.notNull(beanInstance, "Bean instance must not be null");
	Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);
	return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null);
}
 
Example #11
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap());
	assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
	assertFalse(info.indicatesAutowiring());
	assertEquals("DerBigStick", info.getBeanName());
}
 
Example #12
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap());
	assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
	assertFalse(info.indicatesAutowiring());
	assertEquals(WirelessSoap.class.getName(), info.getBeanName());
}
 
Example #13
Source File: AnnotationBeanWiringInfoResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
	Assert.notNull(beanInstance, "Bean instance must not be null");
	Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);
	return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null);
}
 
Example #14
Source File: AnnotationBeanWiringInfoResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable");
	assertNull("Must be returning null for a non-@Configurable class instance", info);
}
 
Example #15
Source File: AnnotationBeanWiringInfoResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new Soap());
	assertNotNull("Must *not* be returning null for a non-@Configurable class instance", info);
}
 
Example #16
Source File: AnnotationBeanWiringInfoResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
	Assert.notNull(beanInstance, "Bean instance must not be null");
	Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);
	return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null);
}
 
Example #17
Source File: AnnotationBeanWiringInfoResolver.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
@Override
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
	Assert.notNull(beanInstance, "Bean instance must not be null");
	Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);
	return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null);
}
 
Example #18
Source File: AnnotationBeanWiringInfoResolver.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
	Assert.notNull(beanInstance, "Bean instance must not be null");
	Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);
	return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null);
}
 
Example #19
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new Soap());
	assertNotNull("Must *not* be returning null for a non-@Configurable class instance", info);
}
 
Example #20
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable");
	assertNull("Must be returning null for a non-@Configurable class instance", info);
}
 
Example #21
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo(new Soap());
	assertNotNull("Must *not* be returning null for a non-@Configurable class instance", info);
}
 
Example #22
Source File: AnnotationBeanWiringInfoResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() {
	AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
	BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable");
	assertNull("Must be returning null for a non-@Configurable class instance", info);
}
 
Example #23
Source File: ConfigurerImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {

        if (null == appContexts) {
            return;
        }

        if (null == bn) {
            bn = getBeanName(beanInstance);
            if (null == bn) {
                return;
            }
        }

        if (checkWildcards) {
            configureWithWildCard(bn, beanInstance);
        }

        final String beanName = bn;
        setBeanWiringInfoResolver(new BeanWiringInfoResolver() {
            public BeanWiringInfo resolveWiringInfo(Object instance) {
                if (!beanName.isEmpty()) {
                    return new BeanWiringInfo(beanName);
                }
                return null;
            }
        });

        for (ApplicationContext appContext : appContexts) {
            if (appContext.containsBean(bn)) {
                this.setBeanFactory(appContext.getAutowireCapableBeanFactory());
            }
        }

        try {
            //this will prevent a call into the AbstractBeanFactory.markBeanAsCreated(...)
            //which saves ALL the names into a HashSet.  For URL based configuration,
            //this can leak memory
            if (beanFactory instanceof AbstractBeanFactory) {
                ((AbstractBeanFactory)beanFactory).getMergedBeanDefinition(bn);
            }
            super.configureBean(beanInstance);
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Successfully performed injection.");
            }
        } catch (NoSuchBeanDefinitionException ex) {
            // users often wonder why the settings in their configuration files seem
            // to have no effect - the most common cause is that they have been using
            // incorrect bean ids
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "NO_MATCHING_BEAN_MSG", beanName);
            }
        }
    }