当前位置: 首页>>代码示例>>Java>>正文


Java AutowiredAnnotationBeanPostProcessor类代码示例

本文整理汇总了Java中org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor的典型用法代码示例。如果您正苦于以下问题:Java AutowiredAnnotationBeanPostProcessor类的具体用法?Java AutowiredAnnotationBeanPostProcessor怎么用?Java AutowiredAnnotationBeanPostProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AutowiredAnnotationBeanPostProcessor类属于org.springframework.beans.factory.annotation包,在下文中一共展示了AutowiredAnnotationBeanPostProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processInjectionBasedOnCurrentContext

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
/**
 * Process {@code @Autowired} injection for the given target object,
 * based on the current web application context.
 * <p>Intended for use as a delegate.
 * @param target the target object to process
 * @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
 */
public static void processInjectionBasedOnCurrentContext(Object target) {
	Assert.notNull(target, "Target object must not be null");
	WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
	if (cc != null) {
		AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
		bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
		bpp.processInjection(target);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Current WebApplicationContext is not available for processing of " +
					ClassUtils.getShortName(target.getClass()) + ": " +
					"Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SpringBeanAutowiringSupport.java

示例2: genericsBasedInjection

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void genericsBasedInjection() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	beanFactory.registerBeanDefinition("annotatedBean", bd);
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryConfiguration.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);

	RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
	assertEquals("Repository<String>", bean.stringRepository.toString());
	assertEquals("Repository<Integer>", bean.integerRepository.toString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ConfigurationClassPostProcessorTests.java

示例3: genericsBasedInjectionWithScoped

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void genericsBasedInjectionWithScoped() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	beanFactory.registerBeanDefinition("annotatedBean", bd);
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ScopedRepositoryConfiguration.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);

	RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
	assertEquals("Repository<String>", bean.stringRepository.toString());
	assertEquals("Repository<Integer>", bean.integerRepository.toString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ConfigurationClassPostProcessorTests.java

示例4: genericsBasedInjectionWithScopedProxy

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void genericsBasedInjectionWithScopedProxy() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	beanFactory.registerBeanDefinition("annotatedBean", bd);
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ScopedProxyRepositoryConfiguration.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.freezeConfiguration();

	RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
	assertEquals("Repository<String>", bean.stringRepository.toString());
	assertEquals("Repository<Integer>", bean.integerRepository.toString());
	assertTrue(AopUtils.isCglibProxy(bean.stringRepository));
	assertTrue(AopUtils.isCglibProxy(bean.integerRepository));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:ConfigurationClassPostProcessorTests.java

示例5: genericsBasedInjectionWithScopedProxyUsingAsm

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void genericsBasedInjectionWithScopedProxyUsingAsm() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class.getName());
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	beanFactory.registerBeanDefinition("annotatedBean", bd);
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ScopedProxyRepositoryConfiguration.class.getName()));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.freezeConfiguration();

	RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
	assertEquals("Repository<String>", bean.stringRepository.toString());
	assertEquals("Repository<Integer>", bean.integerRepository.toString());
	assertTrue(AopUtils.isCglibProxy(bean.stringRepository));
	assertTrue(AopUtils.isCglibProxy(bean.integerRepository));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:ConfigurationClassPostProcessorTests.java

示例6: genericsBasedInjectionWithImplTypeAtInjectionPoint

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void genericsBasedInjectionWithImplTypeAtInjectionPoint() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(SpecificRepositoryInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	beanFactory.registerBeanDefinition("annotatedBean", bd);
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(SpecificRepositoryConfiguration.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.preInstantiateSingletons();

	SpecificRepositoryInjectionBean bean = (SpecificRepositoryInjectionBean) beanFactory.getBean("annotatedBean");
	assertSame(beanFactory.getBean("genericRepo"), bean.genericRepository);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ConfigurationClassPostProcessorTests.java

示例7: genericsBasedInjectionWithFactoryBean

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void genericsBasedInjectionWithFactoryBean() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(RepositoryFactoryBeanInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	beanFactory.registerBeanDefinition("annotatedBean", bd);
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryFactoryBeanConfiguration.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.preInstantiateSingletons();

	RepositoryFactoryBeanInjectionBean bean = (RepositoryFactoryBeanInjectionBean) beanFactory.getBean("annotatedBean");
	assertSame(beanFactory.getBean("&repoFactoryBean"), bean.repositoryFactoryBean);
	assertSame(beanFactory.getBean("&repoFactoryBean"), bean.qualifiedRepositoryFactoryBean);
	assertSame(beanFactory.getBean("&repoFactoryBean"), bean.prefixQualifiedRepositoryFactoryBean);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ConfigurationClassPostProcessorTests.java

示例8: testCircularDependency

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void testCircularDependency() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	beanFactory.registerBeanDefinition("configClass1", new RootBeanDefinition(A.class));
	beanFactory.registerBeanDefinition("configClass2", new RootBeanDefinition(AStrich.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	try {
		beanFactory.preInstantiateSingletons();
		fail("Should have thrown BeanCreationException");
	}
	catch (BeanCreationException ex) {
		assertTrue(ex.getMessage().contains("Circular reference"));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ConfigurationClassPostProcessorTests.java

示例9: testLazyResourceInjectionWithNonExistingTarget

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void testLazyResourceInjectionWithNonExistingTarget() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	RootBeanDefinition bd = new RootBeanDefinition(FieldResourceInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);

	FieldResourceInjectionBean bean = (FieldResourceInjectionBean) bf.getBean("annotatedBean");
	assertNotNull(bean.getTestBean());
	try {
		bean.getTestBean().getName();
		fail("Should have thrown NoSuchBeanDefinitionException");
	}
	catch (NoSuchBeanDefinitionException ex) {
		// expected;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:LazyAutowiredAnnotationBeanPostProcessorTests.java

示例10: removeInjectCache

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
private void removeInjectCache(Object controller) {
    AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor =
            ctx.getBean(AutowiredAnnotationBeanPostProcessor.class);
    Map<String, InjectionMetadata> injectionMetadataMap =
            (Map<String, InjectionMetadata>) ReflectionUtils.getField(injectionMetadataCacheField, autowiredAnnotationBeanPostProcessor);
    injectionMetadataMap.remove(controller.getClass().getName());
}
 
开发者ID:cattientk,项目名称:daros-dynamic,代码行数:8,代码来源:DynamicRegisterGroovyFile.java

示例11: doAutowireBean

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
/**
 * Actually autowire the target bean after construction/passivation.
 * @param target the target bean to autowire
 */
protected void doAutowireBean(Object target) {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	configureBeanPostProcessor(bpp, target);
	bpp.setBeanFactory(getBeanFactory(target));
	bpp.processInjection(target);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:SpringBeanAutowiringInterceptor.java

示例12: scopedProxyTargetMarkedAsNonAutowireCandidate

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void scopedProxyTargetMarkedAsNonAutowireCandidate() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class));
	beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);

	ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean;
	assertTrue(injected instanceof ScopedObject);
	assertSame(beanFactory.getBean("scopedClass"), injected);
	assertSame(beanFactory.getBean(ITestBean.class), injected);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:ConfigurationClassPostProcessorTests.java

示例13: testSelfReferenceExclusionForFactoryMethodOnSameBean

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void testSelfReferenceExclusionForFactoryMethodOnSameBean() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ConcreteConfig.class));
	beanFactory.registerBeanDefinition("serviceBeanProvider", new RootBeanDefinition(ServiceBeanProvider.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	beanFactory.preInstantiateSingletons();

	beanFactory.getBean(ServiceBean.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ConfigurationClassPostProcessorTests.java

示例14: testConfigWithDefaultMethods

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void testConfigWithDefaultMethods() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ConcreteConfigWithDefaultMethods.class));
	beanFactory.registerBeanDefinition("serviceBeanProvider", new RootBeanDefinition(ServiceBeanProvider.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	beanFactory.preInstantiateSingletons();

	beanFactory.getBean(ServiceBean.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ConfigurationClassPostProcessorTests.java

示例15: testConfigWithDefaultMethodsUsingAsm

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; //导入依赖的package包/类
@Test
public void testConfigWithDefaultMethodsUsingAsm() {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(bpp);
	beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ConcreteConfigWithDefaultMethods.class.getName()));
	beanFactory.registerBeanDefinition("serviceBeanProvider", new RootBeanDefinition(ServiceBeanProvider.class.getName()));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	beanFactory.preInstantiateSingletons();

	beanFactory.getBean(ServiceBean.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ConfigurationClassPostProcessorTests.java


注:本文中的org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。