org.springframework.beans.factory.support.BeanDefinitionReader Java Examples

The following examples show how to use org.springframework.beans.factory.support.BeanDefinitionReader. 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: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testQualifiedByParentValue() {
	StaticApplicationContext parent = new StaticApplicationContext();
	GenericBeanDefinition parentLarry = new GenericBeanDefinition();
	parentLarry.setBeanClass(Person.class);
	parentLarry.getPropertyValues().add("name", "ParentLarry");
	parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
	parent.registerBeanDefinition("someLarry", parentLarry);
	GenericBeanDefinition otherLarry = new GenericBeanDefinition();
	otherLarry.setBeanClass(Person.class);
	otherLarry.getPropertyValues().add("name", "OtherLarry");
	otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
	parent.registerBeanDefinition("someOtherLarry", otherLarry);
	parent.refresh();

	StaticApplicationContext context = new StaticApplicationContext(parent);
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
	context.refresh();
	QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("ParentLarry", person.getName());
}
 
Example #2
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
			context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
	resolver.addQualifierType(MultipleAttributeQualifier.class);
	context.registerSingleton("testBean", MultiQualifierClient.class);
	context.refresh();

	MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");

	assertNotNull( testBean.factoryTheta);
	assertNotNull( testBean.implTheta);
}
 
Example #3
Source File: JasperReportsHtmlViewTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void configureExporterParametersWithEncodingFromPropertiesFile() throws Exception {
	GenericWebApplicationContext ac = new GenericWebApplicationContext();
	ac.setServletContext(new MockServletContext());
	BeanDefinitionReader reader = new PropertiesBeanDefinitionReader(ac);
	reader.loadBeanDefinitions(new ClassPathResource("view.properties", getClass()));
	ac.refresh();

	AbstractJasperReportsView view = (AbstractJasperReportsView) ac.getBean("report");
	String encoding = (String) view.getConvertedExporterParameters().get(
		net.sf.jasperreports.engine.export.JRHtmlExporterParameter.CHARACTER_ENCODING);
	assertEquals("UTF-8", encoding);

	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
	view.render(getModel(), request, response);
	assertEquals("Response content type is incorrect", "text/html;charset=UTF-8", response.getContentType());
}
 
Example #4
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
			context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
	resolver.addQualifierType(MultipleAttributeQualifier.class);
	context.registerSingleton("testBean", MultiQualifierClient.class);
	context.refresh();

	MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");

	assertNotNull( testBean.factoryTheta);
	assertNotNull( testBean.implTheta);
}
 
Example #5
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
			context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
	resolver.addQualifierType(MultipleAttributeQualifier.class);
	context.registerSingleton("testBean", MultiQualifierClient.class);
	context.refresh();

	MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");

	assertNotNull( testBean.factoryTheta);
	assertNotNull( testBean.implTheta);
}
 
Example #6
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testQualifiedByParentValue() {
	StaticApplicationContext parent = new StaticApplicationContext();
	GenericBeanDefinition parentLarry = new GenericBeanDefinition();
	parentLarry.setBeanClass(Person.class);
	parentLarry.getPropertyValues().add("name", "ParentLarry");
	parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
	parent.registerBeanDefinition("someLarry", parentLarry);
	GenericBeanDefinition otherLarry = new GenericBeanDefinition();
	otherLarry.setBeanClass(Person.class);
	otherLarry.getPropertyValues().add("name", "OtherLarry");
	otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
	parent.registerBeanDefinition("someOtherLarry", otherLarry);
	parent.refresh();

	StaticApplicationContext context = new StaticApplicationContext(parent);
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
	context.refresh();
	QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("ParentLarry", person.getName());
}
 
Example #7
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByValueTestBean.class);
	context.refresh();
	QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("Larry", person.getName());
}
 
Example #8
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByValueTestBean.class);
	context.refresh();
	QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("Larry", person.getName());
}
 
Example #9
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByParameterName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParameterNameTestBean.class);
	context.refresh();
	QualifiedByParameterNameTestBean testBean = (QualifiedByParameterNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
}
 
Example #10
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByAlias() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAliasTestBean.class);
	context.refresh();
	QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
	Person person = testBean.getStooge();
	assertEquals("LarryBean", person.getName());
}
 
Example #11
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByAnnotation() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAnnotationTestBean.class);
	context.refresh();
	QualifiedByAnnotationTestBean testBean = (QualifiedByAnnotationTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarrySpecial", person.getName());
}
 
Example #12
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByCustomValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByCustomValueTestBean.class);
	context.refresh();
	QualifiedByCustomValueTestBean testBean = (QualifiedByCustomValueTestBean) context.getBean("testBean");
	Person person = testBean.getCurly();
	assertEquals("Curly", person.getName());
}
 
Example #13
Source File: QualifierAnnotationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByFieldName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByFieldNameTestBean.class);
	context.refresh();
	QualifiedByFieldNameTestBean testBean = (QualifiedByFieldNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
}
 
Example #14
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByValueTestBean.class);
	context.refresh();
	QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("Larry", person.getName());
}
 
Example #15
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByAnnotationValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAnnotationValueTestBean.class);
	context.refresh();
	QualifiedByAnnotationValueTestBean testBean = (QualifiedByAnnotationValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarrySpecial", person.getName());
}
 
Example #16
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByBeanName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByBeanNameTestBean.class);
	context.refresh();
	QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
	assertTrue(testBean.myProps != null && testBean.myProps.isEmpty());
}
 
Example #17
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByCustomValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByCustomValueTestBean.class);
	context.refresh();
	QualifiedByCustomValueTestBean testBean = (QualifiedByCustomValueTestBean) context.getBean("testBean");
	Person person = testBean.getCurly();
	assertEquals("Curly", person.getName());
}
 
Example #18
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testNonQualifiedFieldFails() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", NonQualifiedTestBean.class);
	try {
		context.refresh();
		fail("Should have thrown a BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e.getMessage().contains("found 6"));
	}
}
 
Example #19
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByAlias() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAliasTestBean.class);
	context.refresh();
	QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
	Person person = testBean.getStooge();
	assertEquals("LarryBean", person.getName());
}
 
Example #20
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByAnnotation() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAnnotationTestBean.class);
	context.refresh();
	QualifiedByAnnotationTestBean testBean = (QualifiedByAnnotationTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarrySpecial", person.getName());
}
 
Example #21
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByBeanName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByBeanNameTestBean.class);
	context.refresh();
	QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
	assertTrue(testBean.myProps != null && testBean.myProps.isEmpty());
}
 
Example #22
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByFieldName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByFieldNameTestBean.class);
	context.refresh();
	QualifiedByFieldNameTestBean testBean = (QualifiedByFieldNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
}
 
Example #23
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByFieldName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByFieldNameTestBean.class);
	context.refresh();
	QualifiedByFieldNameTestBean testBean = (QualifiedByFieldNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
}
 
Example #24
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByParameterName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParameterNameTestBean.class);
	context.refresh();
	QualifiedByParameterNameTestBean testBean = (QualifiedByParameterNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
}
 
Example #25
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByAlias() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAliasTestBean.class);
	context.refresh();
	QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
	Person person = testBean.getStooge();
	assertEquals("LarryBean", person.getName());
}
 
Example #26
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByAnnotation() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAnnotationTestBean.class);
	context.refresh();
	QualifiedByAnnotationTestBean testBean = (QualifiedByAnnotationTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarrySpecial", person.getName());
}
 
Example #27
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByCustomValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByCustomValueTestBean.class);
	context.refresh();
	QualifiedByCustomValueTestBean testBean = (QualifiedByCustomValueTestBean) context.getBean("testBean");
	Person person = testBean.getCurly();
	assertEquals("Curly", person.getName());
}
 
Example #28
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByAnnotationValue() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAnnotationValueTestBean.class);
	context.refresh();
	QualifiedByAnnotationValueTestBean testBean = (QualifiedByAnnotationValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarrySpecial", person.getName());
}
 
Example #29
Source File: QualifierAnnotationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByAttributesTestBean.class);
	try {
		context.refresh();
		fail("should have thrown a BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e.getMessage().contains("found 6"));
	}
}
 
Example #30
Source File: QualifierAnnotationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testQualifiedByParameterName() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParameterNameTestBean.class);
	context.refresh();
	QualifiedByParameterNameTestBean testBean = (QualifiedByParameterNameTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("LarryBean", person.getName());
}