org.springframework.context.annotation.ConfigurationClassPostProcessor Java Examples

The following examples show how to use org.springframework.context.annotation.ConfigurationClassPostProcessor. 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: ConfigurationClassProcessingTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: ImportTests.java    From java-technology-stack with 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 #3
Source File: BeanAnnotationAttributePropagationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: ImportTests.java    From spring4-understanding with 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 #5
Source File: ImportTests.java    From spring4-understanding with 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 #6
Source File: ImportTests.java    From spring4-understanding with 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 #7
Source File: ConfigurationClassAspectIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: DuplicateConfigurationClassPostProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: ScopingTests.java    From spring4-understanding with 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 #10
Source File: BeanAnnotationAttributePropagationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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 #11
Source File: ImportTests.java    From java-technology-stack with 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 #12
Source File: ImportTests.java    From java-technology-stack with 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 #13
Source File: ConfigurationClassProcessingTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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 #14
Source File: ConfigurationClassAspectIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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 #15
Source File: DuplicateConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #16
Source File: ConfigurationClassProcessingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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 #17
Source File: BeanAnnotationAttributePropagationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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 #18
Source File: ImportTests.java    From spring-analysis-note with 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 #19
Source File: ImportTests.java    From spring-analysis-note with 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 #20
Source File: ImportTests.java    From spring-analysis-note with 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 #21
Source File: ConfigurationClassAspectIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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 #22
Source File: DuplicateConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 #23
Source File: PluginConfigurationPostProcessor.java    From springboot-plugin-framework-parent with Apache License 2.0 4 votes vote down vote up
@Override
public void registry(List<PluginRegistryInfo> pluginRegistryInfos) throws Exception {
    ConfigurationClassPostProcessor configurationClassPostProcessor =
            applicationContext.getBean(ConfigurationClassPostProcessor.class);
    configurationClassPostProcessor.processConfigBeanDefinitions(applicationContext);
}