Polishing

(cherry picked from commit ade139f)
This commit is contained in:
Juergen Hoeller
2016-10-31 19:24:45 +01:00
parent 17d622176d
commit 377780a3c7
17 changed files with 144 additions and 157 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -113,9 +113,9 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
* Add a new BeanFactoryPostProcessor that will get applied to the internal
* bean factory of this application context on refresh, before any of the
* bean definitions get evaluated. To be invoked during context configuration.
* @param beanFactoryPostProcessor the factory processor to register
* @param postProcessor the factory processor to register
*/
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor);
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);
/**
* Add a new ApplicationListener that will be notified on context events

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,6 +47,7 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.HierarchicalMessageSource;
import org.springframework.context.LifecycleProcessor;
@@ -461,8 +462,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
}
@Override
public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor) {
this.beanFactoryPostProcessors.add(beanFactoryPostProcessor);
public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor) {
Assert.notNull(postProcessor, "BeanFactoryPostProcessor must not be null");
this.beanFactoryPostProcessors.add(postProcessor);
}
@@ -476,6 +478,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
@Override
public void addApplicationListener(ApplicationListener<?> listener) {
Assert.notNull(listener, "ApplicationListener must not be null");
if (this.applicationEventMulticaster != null) {
this.applicationEventMulticaster.addApplicationListener(listener);
}
@@ -627,11 +630,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Configure the bean factory with context callbacks.
beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this));
beanFactory.ignoreDependencyInterface(EnvironmentAware.class);
beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class);
beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class);
beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class);
beanFactory.ignoreDependencyInterface(MessageSourceAware.class);
beanFactory.ignoreDependencyInterface(ApplicationContextAware.class);
beanFactory.ignoreDependencyInterface(EnvironmentAware.class);
// BeanFactory interface not registered as resolvable type in a plain factory.
// MessageSource registered (and found for autowiring) as a bean.

View File

@@ -98,8 +98,8 @@ public class FormattingConversionService extends GenericConversionService
static Class<?> getFieldType(Formatter<?> formatter) {
Class<?> fieldType = GenericTypeResolver.resolveTypeArgument(formatter.getClass(), Formatter.class);
if (fieldType == null) {
throw new IllegalArgumentException("Unable to extract parameterized field type argument from Formatter [" +
formatter.getClass().getName() + "]; does the formatter parameterize the <T> generic type?");
throw new IllegalArgumentException("Unable to extract the parameterized field type from Formatter [" +
formatter.getClass().getName() + "]; does the class parameterize the <T> generic type?");
}
return fieldType;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,6 +82,7 @@ public class CustomNamespaceHandlerTests {
private GenericApplicationContext beanFactory;
@Before
public void setUp() throws Exception {
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
@@ -114,7 +115,7 @@ public class CustomNamespaceHandlerTests {
assertTrue(AopUtils.isAopProxy(bean));
Advisor[] advisors = ((Advised) bean).getAdvisors();
assertEquals("Incorrect number of advisors", 1, advisors.length);
assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
}
@Test
@@ -138,8 +139,8 @@ public class CustomNamespaceHandlerTests {
assertTrue(AopUtils.isAopProxy(bean));
Advisor[] advisors = ((Advised) bean).getAdvisors();
assertEquals("Incorrect number of advisors", 2, advisors.length);
assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
assertEquals("Incorrect advice class.", NopInterceptor.class, advisors[1].getAdvice().getClass());
assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
assertEquals("Incorrect advice class", NopInterceptor.class, advisors[1].getAdvice().getClass());
}
@Test
@@ -148,30 +149,21 @@ public class CustomNamespaceHandlerTests {
assertEquals("foo", beanDefinition.getAttribute("objectName"));
}
/**
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
*/
@Test
@Test // SPR-2728
public void testCustomElementNestedWithinUtilList() throws Exception {
List<?> things = (List<?>) this.beanFactory.getBean("list.of.things");
assertNotNull(things);
assertEquals(2, things.size());
}
/**
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
*/
@Test
@Test // SPR-2728
public void testCustomElementNestedWithinUtilSet() throws Exception {
Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things");
assertNotNull(things);
assertEquals(2, things.size());
}
/**
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
*/
@Test
@Test // SPR-2728
public void testCustomElementNestedWithinUtilMap() throws Exception {
Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things");
assertNotNull(things);
@@ -229,6 +221,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionDecoratorForAttribute("object-name", new ObjectNameBeanDefinitionDecorator());
}
private static class TestBeanDefinitionParser implements BeanDefinitionParser {
@Override
@@ -242,11 +235,11 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
definition.setPropertyValues(mpvs);
parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), definition);
return null;
}
}
private static final class PersonDefinitionParser extends AbstractSingleBeanDefinitionParser {
@Override
@@ -261,6 +254,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
}
}
private static class PropertyModifyingBeanDefinitionDecorator implements BeanDefinitionDecorator {
@Override
@@ -277,6 +271,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
}
}
private static class DebugBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator {
@Override
@@ -285,6 +280,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
}
}
private static class NopInterceptorBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator {
@Override
@@ -293,6 +289,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
}
}
private static class ObjectNameBeanDefinitionDecorator implements BeanDefinitionDecorator {
@Override
@@ -302,5 +299,5 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport {
return definition;
}
}
}
}