提交 680afa75 编写于 作者: J Juergen Hoeller

ListableBeanFactory.getBeansOfType does not include null bean entries

Issue: SPR-17034
上级 24a30baa
......@@ -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();
......
/*
* 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));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册