Polish ControllerAdviceBean

This commit is contained in:
Sam Brannen 2019-06-21 17:11:12 +03:00
parent beb454a299
commit 52f1a3aef9
1 changed files with 6 additions and 4 deletions

View File

@ -70,9 +70,10 @@ public class ControllerAdviceBean implements Ordered {
/** /**
* Create a {@code ControllerAdviceBean} using the given bean name. * Create a {@code ControllerAdviceBean} using the given bean name.
* @param beanName the name of the bean * @param beanName the name of the bean
* @param beanFactory a BeanFactory that can be used later to resolve the bean * @param beanFactory a {@code BeanFactory} to retrieve the bean type initially
* and later to resolve the actual bean
*/ */
public ControllerAdviceBean(String beanName, @Nullable BeanFactory beanFactory) { public ControllerAdviceBean(String beanName, BeanFactory beanFactory) {
this((Object) beanName, beanFactory); this((Object) beanName, beanFactory);
} }
@ -83,7 +84,7 @@ public class ControllerAdviceBean implements Ordered {
if (bean instanceof String) { if (bean instanceof String) {
String beanName = (String) bean; String beanName = (String) bean;
Assert.hasText(beanName, "Bean name must not be null"); Assert.hasText(beanName, "Bean name must not be empty");
Assert.notNull(beanFactory, "BeanFactory must not be null"); Assert.notNull(beanFactory, "BeanFactory must not be null");
if (!beanFactory.containsBean(beanName)) { if (!beanFactory.containsBean(beanName)) {
throw new IllegalArgumentException("BeanFactory [" + beanFactory + throw new IllegalArgumentException("BeanFactory [" + beanFactory +
@ -140,7 +141,8 @@ public class ControllerAdviceBean implements Ordered {
} }
/** /**
* Return a bean instance if necessary resolving the bean name through the BeanFactory. * Get the bean instance for this {@code ControllerAdviceBean}, if necessary
* resolving the bean name through the {@link BeanFactory}.
*/ */
public Object resolveBean() { public Object resolveBean() {
return (this.bean instanceof String ? obtainBeanFactory().getBean((String) this.bean) : this.bean); return (this.bean instanceof String ? obtainBeanFactory().getBean((String) this.bean) : this.bean);