Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Mar 6, 2017
1 parent 9fb9a67 commit f5aeac3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,21 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
if (this.beanFactory == null) {
return;
}
if (ObjectUtils.isEmpty(this.beanFactory.getBeanNamesForType(
EmbeddedServletContainerCustomizerBeanPostProcessor.class, true,
false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
EmbeddedServletContainerCustomizerBeanPostProcessor.class);
beanDefinition.setSynthetic(true);
registry.registerBeanDefinition(
"embeddedServletContainerCustomizerBeanPostProcessor",
beanDefinition);
registerSyntheticBeanIfMissing(registry,
"embeddedServletContainerCustomizerBeanPostProcessor",
EmbeddedServletContainerCustomizerBeanPostProcessor.class);
registerSyntheticBeanIfMissing(registry,
"errorPageRegistrarBeanPostProcessor",
ErrorPageRegistrarBeanPostProcessor.class);
}

}
if (ObjectUtils.isEmpty(this.beanFactory.getBeanNamesForType(
ErrorPageRegistrarBeanPostProcessor.class, true, false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
ErrorPageRegistrarBeanPostProcessor.class);
private void registerSyntheticBeanIfMissing(BeanDefinitionRegistry registry,
String name, Class<?> beanClass) {
if (ObjectUtils.isEmpty(
this.beanFactory.getBeanNamesForType(beanClass, true, false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
beanDefinition.setSynthetic(true);
registry.registerBeanDefinition("errorPageRegistrarBeanPostProcessor",
beanDefinition);

registry.registerBeanDefinition(name, beanDefinition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.Assert;

/**
* {@link BeanPostProcessor} that applies all {@link EmbeddedServletContainerCustomizer}s
Expand All @@ -45,6 +46,9 @@ public class EmbeddedServletContainerCustomizerBeanPostProcessor

@Override
public void setBeanFactory(BeanFactory beanFactory) {
Assert.isInstanceOf(ListableBeanFactory.class, beanFactory,
"EmbeddedServletContainerCustomizerBeanPostProcessor can only be used "
+ "with a ListableBeanFactory");
this.beanFactory = (ListableBeanFactory) beanFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.Assert;

/**
* {@link BeanPostProcessor} that applies all {@link ErrorPageRegistrar}s from the bean
Expand All @@ -45,6 +46,9 @@ public class ErrorPageRegistrarBeanPostProcessor

@Override
public void setBeanFactory(BeanFactory beanFactory) {
Assert.isInstanceOf(ListableBeanFactory.class, beanFactory,
"ErrorPageRegistrarBeanPostProcessor can only be used "
+ "with a ListableBeanFactory");
this.beanFactory = (ListableBeanFactory) beanFactory;
}

Expand Down

0 comments on commit f5aeac3

Please sign in to comment.