ListableBeanFactory.getBeansOfType does not include null bean entries

Issue: SPR-17034
This commit is contained in:
Juergen Hoeller 2018-07-14 01:02:39 +02:00
parent 24a30baa2a
commit 680afa75d8
2 changed files with 11 additions and 2 deletions

View File

@ -512,7 +512,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
for (String beanName : beanNames) {
try {
Object beanInstance = getBean(beanName);
result.put(beanName, (beanInstance instanceof NullBean ? null : (T) beanInstance));
if (!(beanInstance instanceof NullBean)) {
result.put(beanName, (T) beanInstance);
}
}
catch (BeanCreationException ex) {
Throwable rootCause = ex.getMostSpecificCause();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -18,6 +18,7 @@ package org.springframework.web.servlet.config.annotation;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -66,6 +67,7 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
import org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor;
@ -121,6 +123,11 @@ public class WebMvcConfigurationSupportTests {
public void emptyHandlerMappings() {
ApplicationContext context = initContext(WebConfig.class);
Map<String, HandlerMapping> handlerMappings = context.getBeansOfType(HandlerMapping.class);
assertFalse(handlerMappings.containsKey("viewControllerHandlerMapping"));
assertFalse(handlerMappings.containsKey("resourceHandlerMapping"));
assertFalse(handlerMappings.containsKey("defaultServletHandlerMapping"));
Object nullBean = context.getBean("viewControllerHandlerMapping");
assertTrue(nullBean.equals(null));