Commit 8529913b authored by Stephane Nicoll's avatar Stephane Nicoll

Improve error message when no ServerProperties bean is found

Closes gh-11511
parent cbefc7bf
/*
* 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));
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment