mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
Closes gh-11448
This commit is contained in:
parent
a46d1416ee
commit
24b5a78e39
@ -113,17 +113,15 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
||||
protected AnnotationAttributes getEndpointAttributes(Class<?> type) {
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils
|
||||
.findMergedAnnotationAttributes(type, Endpoint.class, true, true);
|
||||
if (attributes == null) {
|
||||
attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type,
|
||||
EndpointExtension.class, false, true);
|
||||
if (attributes != null) {
|
||||
return getEndpointAttributes(attributes.getClass("endpoint"));
|
||||
}
|
||||
if (attributes != null) {
|
||||
return attributes;
|
||||
}
|
||||
attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type,
|
||||
EndpointExtension.class, false, true);
|
||||
Assert.state(attributes != null,
|
||||
"OnEnabledEndpointCondition may only be used on @Bean methods that "
|
||||
+ "return an @Endpoint or and @EndpointExtension");
|
||||
return attributes;
|
||||
+ "return an @Endpoint or @EndpointExtension");
|
||||
return getEndpointAttributes(attributes.getClass("endpoint"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointWebExtension;
|
||||
import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
@ -30,7 +29,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link EndpointAutoConfiguration} in a servlet environment.
|
||||
* Tests for {@link HealthEndpointAutoConfiguration} in a servlet environment.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
|
@ -25,10 +25,8 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAu
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.reactive.WebFluxEndpointManagementContextConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementContextAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||
import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
@ -61,10 +59,8 @@ public class WebFluxEndpointCorsIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void corsIsDisabledByDefault() {
|
||||
WebTestClient client = createWebTestClient();
|
||||
System.out.println(new ConditionEvaluationReportMessage(
|
||||
this.context.getBean(ConditionEvaluationReport.class)));
|
||||
client.options().uri("/actuator/beans")
|
||||
createWebTestClient()
|
||||
.options().uri("/actuator/beans")
|
||||
.header("Origin", "spring.example.org")
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.exchange()
|
||||
|
@ -25,10 +25,8 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAu
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
@ -69,12 +67,10 @@ public class WebMvcEndpointCorsIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void corsIsDisabledByDefault() throws Exception {
|
||||
MockMvc mockMvc = createMockMvc();
|
||||
System.out.println(new ConditionEvaluationReportMessage(
|
||||
this.context.getBean(ConditionEvaluationReport.class)));
|
||||
mockMvc.perform(options("/actuator/beans").header("Origin", "foo.example.com")
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")).andExpect(
|
||||
header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
createMockMvc()
|
||||
.perform(options("/actuator/beans").header("Origin", "foo.example.com")
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"))
|
||||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -274,7 +274,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeAcceptCount(TomcatServletWebServerFactory factory,
|
||||
final int acceptCount) {
|
||||
int acceptCount) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
@ -285,7 +285,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeMaxConnections(TomcatServletWebServerFactory factory,
|
||||
final int maxConnections) {
|
||||
int maxConnections) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
@ -332,7 +332,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void customizeMaxThreads(TomcatServletWebServerFactory factory,
|
||||
final int maxThreads) {
|
||||
int maxThreads) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
@ -344,7 +344,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void customizeMinThreads(TomcatServletWebServerFactory factory,
|
||||
final int minSpareThreads) {
|
||||
int minSpareThreads) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
@ -356,7 +356,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void customizeMaxHttpHeaderSize(
|
||||
TomcatServletWebServerFactory factory, final int maxHttpHeaderSize) {
|
||||
TomcatServletWebServerFactory factory, int maxHttpHeaderSize) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
@ -367,7 +367,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpPostSize(
|
||||
TomcatServletWebServerFactory factory, final int maxHttpPostSize) {
|
||||
TomcatServletWebServerFactory factory, int maxHttpPostSize) {
|
||||
factory.addConnectorCustomizers(
|
||||
(connector) -> connector.setMaxPostSize(maxHttpPostSize));
|
||||
}
|
||||
@ -391,14 +391,14 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
private static void customizeRedirectContextRoot(
|
||||
TomcatServletWebServerFactory factory,
|
||||
final boolean redirectContextRoot) {
|
||||
boolean redirectContextRoot) {
|
||||
factory.addContextCustomizers((context) -> context
|
||||
.setMapperContextRootRedirectEnabled(redirectContextRoot));
|
||||
}
|
||||
|
||||
private static void customizeUseRelativeRedirects(
|
||||
TomcatServletWebServerFactory factory,
|
||||
final boolean useRelativeRedirects) {
|
||||
boolean useRelativeRedirects) {
|
||||
factory.addContextCustomizers(
|
||||
(context) -> context.setUseRelativeRedirects(useRelativeRedirects));
|
||||
}
|
||||
@ -474,13 +474,13 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpHeaderSize(
|
||||
UndertowServletWebServerFactory factory, final int maxHttpHeaderSize) {
|
||||
UndertowServletWebServerFactory factory, int maxHttpHeaderSize) {
|
||||
factory.addBuilderCustomizers((builder) -> builder
|
||||
.setServerOption(UndertowOptions.MAX_HEADER_SIZE, maxHttpHeaderSize));
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpPostSize(
|
||||
UndertowServletWebServerFactory factory, final long maxHttpPostSize) {
|
||||
UndertowServletWebServerFactory factory, long maxHttpPostSize) {
|
||||
factory.addBuilderCustomizers((builder) -> builder
|
||||
.setServerOption(UndertowOptions.MAX_ENTITY_SIZE, maxHttpPostSize));
|
||||
}
|
||||
@ -531,7 +531,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpHeaderSize(
|
||||
JettyServletWebServerFactory factory, final int maxHttpHeaderSize) {
|
||||
JettyServletWebServerFactory factory, int maxHttpHeaderSize) {
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
|
||||
@Override
|
||||
@ -578,7 +578,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpPostSize(JettyServletWebServerFactory factory,
|
||||
final int maxHttpPostSize) {
|
||||
int maxHttpPostSize) {
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
|
||||
@Override
|
||||
@ -608,7 +608,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeAccessLog(JettyServletWebServerFactory factory,
|
||||
final ServerProperties.Jetty.Accesslog properties) {
|
||||
ServerProperties.Jetty.Accesslog properties) {
|
||||
factory.addServerCustomizers((server) -> {
|
||||
NCSARequestLog log = new NCSARequestLog();
|
||||
if (properties.getFilename() != null) {
|
||||
|
@ -21,10 +21,8 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
@ -86,8 +84,6 @@ public class ReactiveSessionAutoConfigurationRedisTests
|
||||
private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringSessionUsesRedis(
|
||||
String namespace, RedisFlushMode flushMode) {
|
||||
return (context) -> {
|
||||
System.out.println(new ConditionEvaluationReportMessage(
|
||||
context.getBean(ConditionEvaluationReport.class)));
|
||||
ReactiveRedisOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, ReactiveRedisOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("namespace"))
|
||||
|
@ -165,7 +165,6 @@ content into your application. Rather, pick only the properties that you need.
|
||||
server.compression.min-response-size=2048 # Minimum response size that is required for compression to be performed.
|
||||
server.connection-timeout= # Time that connectors wait for another HTTP request before closing the connection. When not set, the connector's container-specific default is used. Use a value of -1 to indicate no (that is, an infinite) timeout.
|
||||
server.display-name=application # Display name of the application.
|
||||
server.max-http-header-size=0 # Maximum size, in bytes, of the HTTP message header.
|
||||
server.error.include-exception=false # Include the "exception" attribute.
|
||||
server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
|
||||
server.error.path=/error # Path of the error controller.
|
||||
@ -186,6 +185,7 @@ content into your application. Rather, pick only the properties that you need.
|
||||
server.jetty.accesslog.time-zone=GMT # Timezone of the request log.
|
||||
server.jetty.max-http-post-size=0 # Maximum size, in bytes, of the HTTP post or put content.
|
||||
server.jetty.selectors= # Number of selector threads to use.
|
||||
server.max-http-header-size=0 # Maximum size, in bytes, of the HTTP message header.
|
||||
server.port=8080 # Server HTTP port.
|
||||
server.server-header= # Value to use for the Server response header (if empty, no header is sent)
|
||||
server.use-forward-headers= # Whether X-Forwarded-* headers should be applied to the HttpRequest.
|
||||
@ -1124,7 +1124,7 @@ content into your application. Rather, pick only the properties that you need.
|
||||
management.endpoints.web.base-path=/actuator # Base path for Web endpoints. Relative to server.servlet.context-path or management.server.servlet.context-path if management.server.port is configured.
|
||||
management.endpoints.web.path-mapping= # Mapping between endpoint IDs and the path that should expose them.
|
||||
|
||||
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/web/servlet/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties])
|
||||
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/web/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties])
|
||||
management.endpoints.web.cors.allow-credentials= # Whether credentials are supported. When not set, credentials are not supported.
|
||||
management.endpoints.web.cors.allowed-headers= # Comma-separated list of headers to allow in a request. '*' allows all headers.
|
||||
management.endpoints.web.cors.allowed-methods= # Comma-separated list of methods to allow. '*' allows all methods. When not set, defaults to GET.
|
||||
|
@ -303,7 +303,7 @@ configuration permits `GET` and `POST` calls from the `example.com` domain:
|
||||
management.endpoints.web.cors.allowed-methods=GET,POST
|
||||
----
|
||||
|
||||
TIP: See {sc-spring-boot-actuator-autoconfigure}/endpoint/web/servlet/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties] for a complete list of options.
|
||||
TIP: See {sc-spring-boot-actuator-autoconfigure}/endpoint/web/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties] for a complete list of options.
|
||||
|
||||
|
||||
|
||||
|
@ -767,7 +767,7 @@ property is `127.0.0.1`. Similarly, if the `production` profile is active, the
|
||||
profiles are *not* enabled, then the value for the property is `192.168.1.100`.
|
||||
|
||||
If none are explicitly active when the application context starts, the default profiles
|
||||
are activated . So, in the following YAML, we set a value for `security.user.password`
|
||||
are activated. So, in the following YAML, we set a value for `spring.security.user.password`
|
||||
that is *only* available in the "default" profile:
|
||||
|
||||
[source,yaml,indent=0]
|
||||
@ -777,9 +777,9 @@ that is *only* available in the "default" profile:
|
||||
---
|
||||
spring:
|
||||
profiles: default
|
||||
security:
|
||||
user:
|
||||
password: weak
|
||||
security:
|
||||
user:
|
||||
password: weak
|
||||
----
|
||||
|
||||
Whereas, in the following example, the password is always set because it is not attached
|
||||
@ -790,9 +790,10 @@ necessary:
|
||||
----
|
||||
server:
|
||||
port: 8000
|
||||
security:
|
||||
user:
|
||||
password: weak
|
||||
spring:
|
||||
security:
|
||||
user:
|
||||
password: weak
|
||||
----
|
||||
|
||||
Spring profiles designated by using the "spring.profiles" element may optionally be
|
||||
@ -7125,7 +7126,7 @@ application.
|
||||
Each test can use the runner to represents a particular use case. For instance, the sample
|
||||
below invokes a user configuration (`UserConfiguration`) and checks that the
|
||||
auto-configuration backs off properly. Invoking `run` provides a callback context that can
|
||||
be used with `Assert4J`:
|
||||
be used with AssertJ:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
|
@ -17,7 +17,7 @@
|
||||
package org.springframework.boot.autoconfigure;
|
||||
|
||||
/**
|
||||
* Simple service.
|
||||
* Sample service.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user