From 8529913b2478887653e282503548ac063c65bcd7 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 16 Jan 2018 09:53:08 +0100 Subject: [PATCH] Improve error message when no ServerProperties bean is found Closes gh-11511 --- .../web/ServerPropertiesAutoConfiguration.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java index 9ad77035ba..fd8d321f97 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-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. @@ -29,7 +29,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; -import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** @@ -81,9 +80,14 @@ public class ServerPropertiesAutoConfiguration { // a single bean String[] serverPropertiesBeans = this.applicationContext .getBeanNamesForType(ServerProperties.class); - Assert.state(serverPropertiesBeans.length == 1, - "Multiple ServerProperties beans registered " + StringUtils - .arrayToCommaDelimitedString(serverPropertiesBeans)); + if (serverPropertiesBeans.length == 0) { + throw new IllegalStateException("No ServerProperties bean registered"); + } + if (serverPropertiesBeans.length > 1) { + throw new IllegalStateException( + "Multiple ServerProperties beans registered " + StringUtils + .arrayToCommaDelimitedString(serverPropertiesBeans)); + } } }