Skip to content

Commit

Permalink
ListableBeanFactory.getBeansOfType does not include null bean entries
Browse files Browse the repository at this point in the history
Issue: SPR-17034
  • Loading branch information
jhoeller committed Jul 13, 2018
1 parent 24a30ba commit 680afa7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -512,7 +512,9 @@ public <T> Map<String, T> getBeansOfType(@Nullable Class<T> type, boolean includ
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();
Expand Down
@@ -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.
Expand All @@ -18,6 +18,7 @@

import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -66,6 +67,7 @@
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;
Expand Down Expand Up @@ -121,6 +123,11 @@ public void requestMappingHandlerMapping() throws Exception {
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));

Expand Down

0 comments on commit 680afa7

Please sign in to comment.