From c98bb40136ab392c8c6d0ee08c8bba9462d3a49e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 24 Jul 2018 13:36:38 +0200 Subject: [PATCH] Adapt NoSuchBeanDefinitionFailureAnalyzer to framework change This commit adapts to a Spring Framework change based on SPR-11419 and SPR-15338. Rather than throwing an exception when injecting a List or Map of a candidate bean that is not present, an empty collection/map is injected. --- .../NoSuchBeanDefinitionFailureAnalyzer.java | 8 --- ...uchBeanDefinitionFailureAnalyzerTests.java | 54 ------------------- 2 files changed, 62 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java index 2b9237fd8f..beaac6db0a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java @@ -115,14 +115,6 @@ class NoSuchBeanDefinitionFailureAnalyzer } private Class extractBeanType(ResolvableType resolvableType) { - ResolvableType collectionType = resolvableType.asCollection(); - if (!collectionType.equals(ResolvableType.NONE)) { - return collectionType.getGeneric(0).getRawClass(); - } - ResolvableType mapType = resolvableType.asMap(); - if (!mapType.equals(ResolvableType.NONE)) { - return mapType.getGeneric(1).getRawClass(); - } return resolvableType.getRawClass(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java index 98880bed59..10ade52100 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java @@ -17,9 +17,7 @@ package org.springframework.boot.autoconfigure.diagnostics.analyzer; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.Map; import org.junit.Test; @@ -83,30 +81,6 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests { assertActionMissingType(analysis, String.class); } - @Test - public void failureAnalysisForMissingCollectionType() { - FailureAnalysis analysis = analyzeFailure( - createFailure(StringCollectionConfiguration.class)); - assertDescriptionConstructorMissingType(analysis, StringCollectionHandler.class, - 0, String.class); - assertBeanMethodDisabled(analysis, - "did not find property 'spring.string.enabled'", - TestPropertyAutoConfiguration.class, "string"); - assertActionMissingType(analysis, String.class); - } - - @Test - public void failureAnalysisForMissingMapType() { - FailureAnalysis analysis = analyzeFailure( - createFailure(StringMapConfiguration.class)); - assertDescriptionConstructorMissingType(analysis, StringMapHandler.class, 0, - String.class); - assertBeanMethodDisabled(analysis, - "did not find property 'spring.string.enabled'", - TestPropertyAutoConfiguration.class, "string"); - assertActionMissingType(analysis, String.class); - } - @Test public void failureAnalysisForMissingPropertySubType() { FailureAnalysis analysis = analyzeFailure( @@ -281,20 +255,6 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests { } - @Configuration - @ImportAutoConfiguration(TestPropertyAutoConfiguration.class) - @Import(StringCollectionHandler.class) - protected static class StringCollectionConfiguration { - - } - - @Configuration - @ImportAutoConfiguration(TestPropertyAutoConfiguration.class) - @Import(StringMapHandler.class) - protected static class StringMapConfiguration { - - } - @Configuration @ImportAutoConfiguration(TestPropertyAutoConfiguration.class) @Import(NumberHandler.class) @@ -402,18 +362,4 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests { } - protected static class StringCollectionHandler { - - public StringCollectionHandler(Collection collection) { - } - - } - - protected static class StringMapHandler { - - public StringMapHandler(Map map) { - } - - } - }