Java Code Examples for org.springframework.context.support.GenericApplicationContext#getBeanDefinitionCount()

The following examples show how to use org.springframework.context.support.GenericApplicationContext#getBeanDefinitionCount() . 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: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
	int initialBeanCount = context.getBeanDefinitionCount();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);

	assertEquals(6, scannedBeanCount);
	assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
}
 
Example 2
Source File: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	context.registerBeanDefinition("myNamedDao", bd);
	int initialBeanCount = context.getBeanDefinitionCount();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);

	assertEquals(6, scannedBeanCount);
	assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
}
 
Example 3
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
	int initialBeanCount = context.getBeanDefinitionCount();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);

	assertEquals(6, scannedBeanCount);
	assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
}
 
Example 4
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	context.registerBeanDefinition("myNamedDao", bd);
	int initialBeanCount = context.getBeanDefinitionCount();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);

	assertEquals(6, scannedBeanCount);
	assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
}
 
Example 5
Source File: ClassPathBeanDefinitionScannerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
	int initialBeanCount = context.getBeanDefinitionCount();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(5, scannedBeanCount);
	assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
}
 
Example 6
Source File: ClassPathBeanDefinitionScannerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	context.registerBeanDefinition("myNamedDao", bd);
	int initialBeanCount = context.getBeanDefinitionCount();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(5, scannedBeanCount);
	assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
}
 
Example 7
Source File: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testMultipleScanCalls() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	int initialBeanCount = context.getBeanDefinitionCount();
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, scannedBeanCount);
	assertEquals(scannedBeanCount, context.getBeanDefinitionCount() - initialBeanCount);
	int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
	assertEquals(initialBeanCount + scannedBeanCount + addedBeanCount, context.getBeanDefinitionCount());
}
 
Example 8
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testMultipleScanCalls() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	int initialBeanCount = context.getBeanDefinitionCount();
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, scannedBeanCount);
	assertEquals(scannedBeanCount, context.getBeanDefinitionCount() - initialBeanCount);
	int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
	assertEquals(initialBeanCount + scannedBeanCount + addedBeanCount, context.getBeanDefinitionCount());
}
 
Example 9
Source File: ClassPathBeanDefinitionScannerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleScanCalls() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	int initialBeanCount = context.getBeanDefinitionCount();
	int scannedBeanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, scannedBeanCount);
	assertEquals(scannedBeanCount, context.getBeanDefinitionCount() - initialBeanCount);
	int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
	assertEquals(initialBeanCount + scannedBeanCount + addedBeanCount, context.getBeanDefinitionCount());
}