Java Code Examples for org.springframework.context.annotation.ConfigurationClassPostProcessor

The following examples show how to use org.springframework.context.annotation.ConfigurationClassPostProcessor. These examples are extracted from open source projects. 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
/**
 * Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition} for
 * each of the given {@link Configuration} <var>configClasses</var>, and then
 * post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
 * When complete, the factory is ready to service requests for any {@link Bean} methods
 * declared by <var>configClasses</var>.
 */
private ListableBeanFactory initBeanFactory(Class<?>... configClasses) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	for (Class<?> configClass : configClasses) {
		String configBeanName = configClass.getName();
		factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
	}
	ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
	ccpp.postProcessBeanDefinitionRegistry(factory);
	ccpp.postProcessBeanFactory(factory);
	RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
	rapp.setBeanFactory(factory);
	factory.addBeanPostProcessor(rapp);
	factory.freezeConfiguration();
	return factory;
}
 
Example 2
/**
 * Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition}
 * for each of the given {@link Configuration} {@code configClasses}, and then
 * post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
 * When complete, the factory is ready to service requests for any {@link Bean} methods
 * declared by {@code configClasses}.
 */
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	for (Class<?> configClass : configClasses) {
		String configBeanName = configClass.getName();
		factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
	}
	ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
	ccpp.postProcessBeanDefinitionRegistry(factory);
	ccpp.postProcessBeanFactory(factory);
	factory.freezeConfiguration();
	return factory;
}
 
Example 3
@Test
public void repro() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.registerBeanDefinition("a", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
	ctx.registerBeanDefinition("b", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
	ctx.registerBeanDefinition("myConfig", new RootBeanDefinition(Config.class));
	ctx.refresh();
}
 
Example 4
private void assertAdviceWasApplied(Class<?> configClass) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
			new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
	GenericApplicationContext ctx = new GenericApplicationContext(factory);
	ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
	ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	ctx.refresh();

	TestBean testBean = ctx.getBean("testBean", TestBean.class);
	assertThat(testBean.getName(), equalTo("name"));
	testBean.absquatulate();
	assertThat(testBean.getName(), equalTo("advisedName"));
}
 
Example 5
Source Project: spring-analysis-note   Source File: ImportTests.java    License: MIT License 5 votes vote down vote up
private DefaultListableBeanFactory processConfigurationClasses(Class<?>... classes) {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	for (Class<?> clazz : classes) {
		beanFactory.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
	}
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	return beanFactory;
}
 
Example 6
Source Project: spring-analysis-note   Source File: ImportTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testProcessImportsWithAsm() {
	int configClasses = 2;
	int beansInClasses = 2;
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithImportAnnotation.class.getName()));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	assertThat(beanFactory.getBeanDefinitionCount(), equalTo(configClasses + beansInClasses));
}
 
Example 7
Source Project: spring-analysis-note   Source File: ImportTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(
			WithMultipleArgumentsThatWillCauseDuplication.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	assertThat(beanFactory.getBeanDefinitionCount(), equalTo(4));
	assertThat(beanFactory.getBean("foo", ITestBean.class).getName(), equalTo("foo2"));
}
 
Example 8
private AbstractBeanDefinition beanDef(Class<?> configClass) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(factory);
	return (AbstractBeanDefinition) factory.getBeanDefinition("foo");
}
 
Example 9
/**
 * Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition}
 * for each of the given {@link Configuration} {@code configClasses}, and then
 * post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
 * When complete, the factory is ready to service requests for any {@link Bean} methods
 * declared by {@code configClasses}.
 */
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	for (Class<?> configClass : configClasses) {
		String configBeanName = configClass.getName();
		factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
	}
	ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
	ccpp.postProcessBeanDefinitionRegistry(factory);
	ccpp.postProcessBeanFactory(factory);
	factory.freezeConfiguration();
	return factory;
}
 
Example 10
@Test
public void repro() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.registerBeanDefinition("a", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
	ctx.registerBeanDefinition("b", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
	ctx.registerBeanDefinition("myConfig", new RootBeanDefinition(Config.class));
	ctx.refresh();
}
 
Example 11
private void assertAdviceWasApplied(Class<?> configClass) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
			new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
	GenericApplicationContext ctx = new GenericApplicationContext(factory);
	ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
	ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	ctx.refresh();

	TestBean testBean = ctx.getBean("testBean", TestBean.class);
	assertThat(testBean.getName(), equalTo("name"));
	testBean.absquatulate();
	assertThat(testBean.getName(), equalTo("advisedName"));
}
 
Example 12
Source Project: java-technology-stack   Source File: ImportTests.java    License: MIT License 5 votes vote down vote up
private DefaultListableBeanFactory processConfigurationClasses(Class<?>... classes) {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	for (Class<?> clazz : classes) {
		beanFactory.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
	}
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	return beanFactory;
}
 
Example 13
Source Project: java-technology-stack   Source File: ImportTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testProcessImportsWithAsm() {
	int configClasses = 2;
	int beansInClasses = 2;
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithImportAnnotation.class.getName()));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	assertThat(beanFactory.getBeanDefinitionCount(), equalTo(configClasses + beansInClasses));
}
 
Example 14
Source Project: java-technology-stack   Source File: ImportTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(
			WithMultipleArgumentsThatWillCauseDuplication.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	assertThat(beanFactory.getBeanDefinitionCount(), equalTo(4));
	assertThat(beanFactory.getBean("foo", ITestBean.class).getName(), equalTo("foo2"));
}
 
Example 15
private AbstractBeanDefinition beanDef(Class<?> configClass) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(factory);
	return (AbstractBeanDefinition) factory.getBeanDefinition("foo");
}
 
Example 16
Source Project: spring4-understanding   Source File: ScopingTests.java    License: Apache License 2.0 5 votes vote down vote up
private GenericApplicationContext createContext(Class<?> configClass) {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	if (customScope != null) {
		beanFactory.registerScope(SCOPE, customScope);
	}
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	GenericApplicationContext ctx = new GenericApplicationContext(beanFactory);
	ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
	ctx.refresh();
	return ctx;
}
 
Example 17
@Test
public void repro() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.registerBeanDefinition("a", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
	ctx.registerBeanDefinition("b", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
	ctx.registerBeanDefinition("myConfig", new RootBeanDefinition(Config.class));
	ctx.refresh();
}
 
Example 18
private void assertAdviceWasApplied(Class<?> configClass) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
			new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
	GenericApplicationContext ctx = new GenericApplicationContext(factory);
	ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
	ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	ctx.refresh();

	TestBean testBean = ctx.getBean("testBean", TestBean.class);
	assertThat(testBean.getName(), equalTo("name"));
	testBean.absquatulate();
	assertThat(testBean.getName(), equalTo("advisedName"));
}
 
Example 19
Source Project: spring4-understanding   Source File: ImportTests.java    License: Apache License 2.0 5 votes vote down vote up
private DefaultListableBeanFactory processConfigurationClasses(Class<?>... classes) {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	for (Class<?> clazz : classes) {
		beanFactory.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
	}
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	return beanFactory;
}
 
Example 20
Source Project: spring4-understanding   Source File: ImportTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessImportsWithAsm() {
	int configClasses = 2;
	int beansInClasses = 2;
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithImportAnnotation.class.getName()));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	assertThat(beanFactory.getBeanDefinitionCount(), equalTo(configClasses + beansInClasses));
}
 
Example 21
Source Project: spring4-understanding   Source File: ImportTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(
			WithMultipleArgumentsThatWillCauseDuplication.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	assertThat(beanFactory.getBeanDefinitionCount(), equalTo(4));
	assertThat(beanFactory.getBean("foo", ITestBean.class).getName(), equalTo("foo2"));
}
 
Example 22
private AbstractBeanDefinition beanDef(Class<?> configClass) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerBeanDefinition("config", new RootBeanDefinition(configClass));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(factory);
	return (AbstractBeanDefinition) factory.getBeanDefinition("foo");
}
 
Example 23
@Override
public void registry(List<PluginRegistryInfo> pluginRegistryInfos) throws Exception {
    ConfigurationClassPostProcessor configurationClassPostProcessor =
            applicationContext.getBean(ConfigurationClassPostProcessor.class);
    configurationClassPostProcessor.processConfigBeanDefinitions(applicationContext);
}