@Test public void viaContextRegistration_FromPackageOfConfigClass() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ComponentScanAnnotatedConfigWithImplicitBasePackage.class); ctx.refresh(); ctx.getBean(ComponentScanAnnotatedConfigWithImplicitBasePackage.class); assertThat( "config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfigWithImplicitBasePackage"), is(true)); assertThat( "@ComponentScan annotated @Configuration class registered directly against " + "AnnotationConfigApplicationContext did not trigger component scanning as expected", ctx.containsBean("scannedComponent"), is(true)); }
@Test public void viaContextRegistration_WithValueAttribute() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ComponentScanAnnotatedConfig_WithValueAttribute.class); ctx.refresh(); ctx.getBean(ComponentScanAnnotatedConfig_WithValueAttribute.class); ctx.getBean(TestBean.class); assertThat( "config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfig_WithValueAttribute"), is(true)); assertThat( "@ComponentScan annotated @Configuration class registered directly against " + "AnnotationConfigApplicationContext did not trigger component scanning as expected", ctx.containsBean("fooServiceImpl"), is(true)); }
@Test public void viaContextRegistration_WithLocallyDeclaredComposedAnnotation() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ComposedAnnotationConfig.class); ctx.refresh(); ctx.getBean(ComposedAnnotationConfig.class); ctx.getBean(SimpleComponent.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)); }