org.springframework.context.annotation.componentscan.simple.SimpleComponent Java Examples

The following examples show how to use org.springframework.context.annotation.componentscan.simple.SimpleComponent. 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: ComponentScanAndImportAnnotationInteractionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void componentScanOverlapsWithImportUsingAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config1", new RootBeanDefinition(Config1.class.getName()));
	ctx.registerBeanDefinition("config2", new RootBeanDefinition(Config2.class.getName()));
	ctx.refresh(); // no conflicts found trying to register SimpleComponent
	ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
}
 
Example #2
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void componentScanViaImportUsingScan() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.scan("org.springframework.context.annotation.componentscan.importing");
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #3
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void componentScanViaImportUsingAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config4", new RootBeanDefinition(Config3.class.getName()));
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #4
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void componentScanViaImport() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(Config3.class);
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #5
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void componentScanOverlapsWithImportUsingAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config1", new RootBeanDefinition(Config1.class.getName()));
	ctx.registerBeanDefinition("config2", new RootBeanDefinition(Config2.class.getName()));
	ctx.refresh(); // no conflicts found trying to register SimpleComponent
	ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
}
 
Example #6
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void componentScanOverlapsWithImport() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(Config1.class);
	ctx.register(Config2.class);
	ctx.refresh(); // no conflicts found trying to register SimpleComponent
	ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
}
 
Example #7
Source File: ConfigurationClassPostProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void assertSupportForComposedAnnotationWithExclude(RootBeanDefinition beanDefinition) {
	beanFactory.registerBeanDefinition("config", beanDefinition);
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.setEnvironment(new StandardEnvironment());
	pp.postProcessBeanFactory(beanFactory);
	try {
		beanFactory.getBean(SimpleComponent.class);
		fail("Should have thrown NoSuchBeanDefinitionException");
	}
	catch (NoSuchBeanDefinitionException ex) {
		// expected
	}
}
 
Example #8
Source File: ConfigurationClassPostProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void assertSupportForComposedAnnotation(RootBeanDefinition beanDefinition) {
	beanFactory.registerBeanDefinition("config", beanDefinition);
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.setEnvironment(new StandardEnvironment());
	pp.postProcessBeanFactory(beanFactory);
	SimpleComponent simpleComponent = beanFactory.getBean(SimpleComponent.class);
	assertNotNull(simpleComponent);
}
 
Example #9
Source File: ComponentScanAnnotationIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void viaContextRegistration_WithComposedAnnotation() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(ComposedAnnotationConfig.class);
	ctx.refresh();
	ctx.getBean(ComposedAnnotationConfig.class);
	ctx.getBean(SimpleComponent.class);
	ctx.getBean(ClassWithNestedComponents.NestedComponent.class);
	ctx.getBean(ClassWithNestedComponents.OtherNestedComponent.class);
	assertThat("config class bean not found",
			ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig"), is(true));
	assertThat("@ComponentScan annotated @Configuration class registered directly against " +
					"AnnotationConfigApplicationContext did not trigger component scanning as expected",
			ctx.containsBean("simpleComponent"), is(true));
}
 
Example #10
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void circularImportViaComponentScan() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config", new RootBeanDefinition(ImportingConfig.class.getName()));
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #11
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void componentScanViaImportUsingScan() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.scan("org.springframework.context.annotation.componentscan.importing");
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #12
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void componentScanViaImportUsingAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config", new RootBeanDefinition(Config3.class.getName()));
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #13
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void componentScanViaImport() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(Config3.class);
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #14
Source File: ComponentScanAnnotationIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void viaContextRegistration_WithComposedAnnotation() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(ComposedAnnotationConfig.class);
	ctx.refresh();
	ctx.getBean(ComposedAnnotationConfig.class);
	ctx.getBean(SimpleComponent.class);
	ctx.getBean(ClassWithNestedComponents.NestedComponent.class);
	ctx.getBean(ClassWithNestedComponents.OtherNestedComponent.class);
	assertThat("config class bean not found",
			ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig"), is(true));
	assertThat("@ComponentScan annotated @Configuration class registered directly against " +
					"AnnotationConfigApplicationContext did not trigger component scanning as expected",
			ctx.containsBean("simpleComponent"), is(true));
}
 
Example #15
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void componentScanOverlapsWithImport() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(Config1.class);
	ctx.register(Config2.class);
	ctx.refresh(); // no conflicts found trying to register SimpleComponent
	ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
}
 
Example #16
Source File: ConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertSupportForComposedAnnotationWithExclude(RootBeanDefinition beanDefinition) {
	beanFactory.registerBeanDefinition("config", beanDefinition);
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.setEnvironment(new StandardEnvironment());
	pp.postProcessBeanFactory(beanFactory);
	try {
		beanFactory.getBean(SimpleComponent.class);
		fail("Should have thrown NoSuchBeanDefinitionException");
	}
	catch (NoSuchBeanDefinitionException ex) {
		// expected
	}
}
 
Example #17
Source File: ConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertSupportForComposedAnnotation(RootBeanDefinition beanDefinition) {
	beanFactory.registerBeanDefinition("config", beanDefinition);
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.setEnvironment(new StandardEnvironment());
	pp.postProcessBeanFactory(beanFactory);
	SimpleComponent simpleComponent = beanFactory.getBean(SimpleComponent.class);
	assertNotNull(simpleComponent);
}
 
Example #18
Source File: ComponentScanAnnotationIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void viaContextRegistration_WithComposedAnnotation() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(ComposedAnnotationConfig.class);
	ctx.refresh();
	ctx.getBean(ComposedAnnotationConfig.class);
	ctx.getBean(SimpleComponent.class);
	ctx.getBean(ClassWithNestedComponents.NestedComponent.class);
	ctx.getBean(ClassWithNestedComponents.OtherNestedComponent.class);
	assertThat("config class bean not found",
			ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig"), is(true));
	assertThat("@ComponentScan annotated @Configuration class registered directly against " +
					"AnnotationConfigApplicationContext did not trigger component scanning as expected",
			ctx.containsBean("simpleComponent"), is(true));
}
 
Example #19
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void circularImportViaComponentScan() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config", new RootBeanDefinition(ImportingConfig.class.getName()));
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #20
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void componentScanViaImportUsingScan() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.scan("org.springframework.context.annotation.componentscan.importing");
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #21
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void componentScanViaImportUsingAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config", new RootBeanDefinition(Config3.class.getName()));
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #22
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void componentScanViaImport() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(Config3.class);
	ctx.refresh();
	ctx.getBean(SimpleComponent.class);
}
 
Example #23
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void componentScanOverlapsWithImportUsingAsm() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.registerBeanDefinition("config1", new RootBeanDefinition(Config1.class.getName()));
	ctx.registerBeanDefinition("config2", new RootBeanDefinition(Config2.class.getName()));
	ctx.refresh(); // no conflicts found trying to register SimpleComponent
	ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
}
 
Example #24
Source File: ComponentScanAndImportAnnotationInteractionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void componentScanOverlapsWithImport() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(Config1.class);
	ctx.register(Config2.class);
	ctx.refresh(); // no conflicts found trying to register SimpleComponent
	ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
}
 
Example #25
Source File: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertSupportForComposedAnnotationWithExclude(RootBeanDefinition beanDefinition) {
	beanFactory.registerBeanDefinition("config", beanDefinition);
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.setEnvironment(new StandardEnvironment());
	pp.postProcessBeanFactory(beanFactory);
	try {
		beanFactory.getBean(SimpleComponent.class);
		fail("Should have thrown NoSuchBeanDefinitionException");
	}
	catch (NoSuchBeanDefinitionException ex) {
		// expected
	}
}
 
Example #26
Source File: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertSupportForComposedAnnotation(RootBeanDefinition beanDefinition) {
	beanFactory.registerBeanDefinition("config", beanDefinition);
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.setEnvironment(new StandardEnvironment());
	pp.postProcessBeanFactory(beanFactory);
	SimpleComponent simpleComponent = beanFactory.getBean(SimpleComponent.class);
	assertNotNull(simpleComponent);
}