Browse Source

Improve error message when no ServerProperties bean is found

Closes gh-11511
pull/11625/merge
Stephane Nicoll 8 years ago
parent
commit
8529913b24
  1. 14
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java

14
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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));
}
}
}

Loading…
Cancel
Save