mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish
See gh-12812
This commit is contained in:
parent
a9020df9b9
commit
f03849d502
@ -25,13 +25,12 @@ import io.micrometer.core.instrument.binder.MeterBinder;
|
|||||||
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
||||||
import io.micrometer.core.instrument.config.MeterFilter;
|
import io.micrometer.core.instrument.config.MeterFilter;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
||||||
import org.springframework.boot.util.LambdaSafe;
|
import org.springframework.boot.util.LambdaSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link BeanPostProcessor} to apply {@link MeterRegistryCustomizer customizers},
|
* Configurer to apply {@link MeterRegistryCustomizer customizers},
|
||||||
* {@link MeterFilter filters}, {@link MeterBinder binders} and {@link Metrics#addRegistry
|
* {@link MeterFilter filters}, {@link MeterBinder binders} and {@link Metrics#addRegistry
|
||||||
* global registration} to {@link MeterRegistry meter registries}. This post processor
|
* global registration} to {@link MeterRegistry meter registries}. This configurer
|
||||||
* intentionally skips {@link CompositeMeterRegistry} with the assumptions that the
|
* intentionally skips {@link CompositeMeterRegistry} with the assumptions that the
|
||||||
* registries it contains are beans and will be customized directly.
|
* registries it contains are beans and will be customized directly.
|
||||||
*
|
*
|
||||||
|
@ -34,7 +34,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for instrumentation of Spring
|
* {@link EnableAutoConfiguration Auto-configuration} for instrumentation of Spring
|
||||||
* Webflux MVC annotation-based programming model request mappings.
|
* WebFlux MVC annotation-based programming model request mappings.
|
||||||
*
|
*
|
||||||
* @author Jon Schneider
|
* @author Jon Schneider
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
|
@ -85,7 +85,7 @@ public class MeterRegistryCustomizerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MeterRegistryCustomizer<PrometheusMeterRegistry> prometehusOnlyCommonTags() {
|
public MeterRegistryCustomizer<PrometheusMeterRegistry> prometheusOnlyCommonTags() {
|
||||||
return (registry) -> registry.config().commonTags("job", "myjob");
|
return (registry) -> registry.config().commonTags("job", "myjob");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +80,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void autoConfigurationCanBeDisabled() {
|
public void autoConfigurationCanBeDisabled() {
|
||||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||||
.withPropertyValues("management.metrics.export.newrelic.enabled=false",
|
.withPropertyValues("management.metrics.export.newrelic.enabled=false")
|
||||||
"management.metrics.export.newrelic.api-key=abcde",
|
|
||||||
"management.metrics.export.newrelic.account-id=12345")
|
|
||||||
.run((context) -> assertThat(context)
|
.run((context) -> assertThat(context)
|
||||||
.doesNotHaveBean(NewRelicMeterRegistry.class)
|
.doesNotHaveBean(NewRelicMeterRegistry.class)
|
||||||
.doesNotHaveBean(NewRelicConfig.class));
|
.doesNotHaveBean(NewRelicConfig.class));
|
||||||
|
@ -72,7 +72,6 @@ public class SignalFxMetricsExportAutoConfigurationTests {
|
|||||||
public void autoConfigurationCanBeDisabled() {
|
public void autoConfigurationCanBeDisabled() {
|
||||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"management.metrics.export.signalfx.access-token=abcde",
|
|
||||||
"management.metrics.export.signalfx.enabled=false")
|
"management.metrics.export.signalfx.enabled=false")
|
||||||
.run((context) -> assertThat(context)
|
.run((context) -> assertThat(context)
|
||||||
.doesNotHaveBean(SignalFxMeterRegistry.class)
|
.doesNotHaveBean(SignalFxMeterRegistry.class)
|
||||||
|
@ -50,7 +50,7 @@ public abstract class AbstractHealthIndicator implements HealthIndicator {
|
|||||||
* Create a new {@link AbstractHealthIndicator} instance with a default
|
* Create a new {@link AbstractHealthIndicator} instance with a default
|
||||||
* {@code healthCheckFailedMessage}.
|
* {@code healthCheckFailedMessage}.
|
||||||
*/
|
*/
|
||||||
public AbstractHealthIndicator() {
|
protected AbstractHealthIndicator() {
|
||||||
this(NO_MESSAGE);
|
this(NO_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import org.springframework.web.server.WebFilter;
|
|||||||
import org.springframework.web.server.WebFilterChain;
|
import org.springframework.web.server.WebFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intercepts incoming HTTP requests modeled with the Webflux annotation-based programming
|
* Intercepts incoming HTTP requests modeled with the WebFlux annotation-based programming
|
||||||
* model.
|
* model.
|
||||||
*
|
*
|
||||||
* @author Jon Schneider
|
* @author Jon Schneider
|
||||||
|
@ -551,7 +551,7 @@ JMX or an HTTP request is converted to the required types using an instance of
|
|||||||
|
|
||||||
[[production-ready-endpoints-custom-web]]
|
[[production-ready-endpoints-custom-web]]
|
||||||
==== Custom Web Endpoints
|
==== Custom Web Endpoints
|
||||||
Operations on a `@Endpoint`, `@WebEndpoint`, or `@WebEndpointExtension` are automatically
|
Operations on an `@Endpoint`, `@WebEndpoint`, or `@WebEndpointExtension` are automatically
|
||||||
exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux.
|
exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux.
|
||||||
|
|
||||||
|
|
||||||
@ -673,7 +673,7 @@ possible.
|
|||||||
==== Controller endpoints
|
==== Controller endpoints
|
||||||
`@ControllerEndpoint` and `@RestControllerEndpoint` can be used to implement an endpoint
|
`@ControllerEndpoint` and `@RestControllerEndpoint` can be used to implement an endpoint
|
||||||
that is only exposed by Spring MVC or Spring WebFlux. Methods are mapped using the
|
that is only exposed by Spring MVC or Spring WebFlux. Methods are mapped using the
|
||||||
standard annotations Spring MVC and Spring WebFlux annotations such as `@RequestMapping`
|
standard annotations for Spring MVC and Spring WebFlux such as `@RequestMapping`
|
||||||
and `@GetMapping`, with the endpoint's ID being used as a prefix for the path. Controller
|
and `@GetMapping`, with the endpoint's ID being used as a prefix for the path. Controller
|
||||||
endpoints provide deeper integration with Spring's web frameworks but at the expense of
|
endpoints provide deeper integration with Spring's web frameworks but at the expense of
|
||||||
portability. The `@Endpoint` and `@WebEndpoint` annotations should be preferred whenever
|
portability. The `@Endpoint` and `@WebEndpoint` annotations should be preferred whenever
|
||||||
@ -1763,7 +1763,7 @@ is required. A `CacheMetricsRegistrar` bean is made available to make that proce
|
|||||||
|
|
||||||
[[production-ready-metrics-jdbc]]
|
[[production-ready-metrics-jdbc]]
|
||||||
==== DataSource Metrics
|
==== DataSource Metrics
|
||||||
Auto-configuration enables the instrumentation of all available DataSource` objects with a
|
Auto-configuration enables the instrumentation of all available `DataSource` objects with a
|
||||||
metric named `jdbc`. Data source instrumentation results in gauges representing the
|
metric named `jdbc`. Data source instrumentation results in gauges representing the
|
||||||
currently active, maximum allowed, and minimum allowed connections in the pool. Each of
|
currently active, maximum allowed, and minimum allowed connections in the pool. Each of
|
||||||
these gauges has a name that is prefixed by `jdbc`.
|
these gauges has a name that is prefixed by `jdbc`.
|
||||||
|
@ -18,7 +18,6 @@ package org.springframework.boot.docs.web.security;
|
|||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
|
import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
|
||||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||||
|
|
||||||
@ -27,20 +26,19 @@ import org.springframework.security.web.server.SecurityWebFilterChain;
|
|||||||
*
|
*
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
*/
|
*/
|
||||||
@EnableWebFluxSecurity
|
|
||||||
public class CustomWebFluxSecurityExample {
|
public class CustomWebFluxSecurityExample {
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
// tag::configuration[]
|
// tag::configuration[]
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||||
http
|
return http
|
||||||
.authorizeExchange()
|
.authorizeExchange()
|
||||||
.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
|
.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
|
||||||
.pathMatchers("/foo", "/bar")
|
.pathMatchers("/foo", "/bar")
|
||||||
.authenticated().and()
|
.authenticated().and()
|
||||||
.formLogin();
|
.formLogin().and()
|
||||||
return http.build();
|
.build();
|
||||||
}
|
}
|
||||||
// end::configuration[]
|
// end::configuration[]
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
@ -74,8 +74,7 @@ public class WebTestClientSpringBootTestIntegrationTests {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||||
http.authorizeExchange().anyExchange().permitAll();
|
return http.authorizeExchange().anyExchange().permitAll().and().build();
|
||||||
return http.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public class ApplicationContextAssert<C extends ApplicationContext>
|
|||||||
* Verifies that the application context contains a single bean with the given type.
|
* Verifies that the application context contains a single bean with the given type.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: <pre class="code">
|
* Example: <pre class="code">
|
||||||
* assertThat(context).hasSingleBean(Foo.class); </pre>
|
* assertThat(context).hasSingleBean(Foo.class, Scope.NO_ANCESTORS); </pre>
|
||||||
* @param type the bean type
|
* @param type the bean type
|
||||||
* @param scope the scope of the assertion
|
* @param scope the scope of the assertion
|
||||||
* @return {@code this} assertion object.
|
* @return {@code this} assertion object.
|
||||||
@ -159,7 +159,7 @@ public class ApplicationContextAssert<C extends ApplicationContext>
|
|||||||
* Verifies that the application context does not contain any beans of the given type.
|
* Verifies that the application context does not contain any beans of the given type.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: <pre class="code">
|
* Example: <pre class="code">
|
||||||
* assertThat(context).doesNotHaveBean(Foo.class); </pre>
|
* assertThat(context).doesNotHaveBean(Foo.class, Scope.NO_ANCESTORS); </pre>
|
||||||
* @param type the bean type
|
* @param type the bean type
|
||||||
* @param scope the scope of the assertion
|
* @param scope the scope of the assertion
|
||||||
* @return {@code this} assertion object.
|
* @return {@code this} assertion object.
|
||||||
@ -255,8 +255,8 @@ public class ApplicationContextAssert<C extends ApplicationContext>
|
|||||||
* assert on {@code null} is returned.
|
* assert on {@code null} is returned.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: <pre class="code">
|
* Example: <pre class="code">
|
||||||
* assertThat(context).getBean(Foo.class).isInstanceOf(DefaultFoo.class);
|
* assertThat(context).getBean(Foo.class, Scope.NO_ANCESTORS).isInstanceOf(DefaultFoo.class);
|
||||||
* assertThat(context).getBean(Bar.class).isNull();</pre>
|
* assertThat(context).getBean(Bar.class, Scope.NO_ANCESTORS).isNull();</pre>
|
||||||
* @param <T> the bean type
|
* @param <T> the bean type
|
||||||
* @param type the bean type
|
* @param type the bean type
|
||||||
* @param scope the scope of the assertion
|
* @param scope the scope of the assertion
|
||||||
@ -374,7 +374,7 @@ public class ApplicationContextAssert<C extends ApplicationContext>
|
|||||||
* can be found an assert on an empty {@code map} is returned.
|
* can be found an assert on an empty {@code map} is returned.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: <pre class="code">
|
* Example: <pre class="code">
|
||||||
* assertThat(context).getBeans(Foo.class).containsKey("foo");
|
* assertThat(context).getBeans(Foo.class, Scope.NO_ANCESTORS).containsKey("foo");
|
||||||
* </pre>
|
* </pre>
|
||||||
* @param <T> the bean type
|
* @param <T> the bean type
|
||||||
* @param type the bean type
|
* @param type the bean type
|
||||||
|
@ -142,7 +142,7 @@ public class TestRestTemplateTests {
|
|||||||
.willReturn(new DefaultUriBuilderFactory());
|
.willReturn(new DefaultUriBuilderFactory());
|
||||||
RestTemplateBuilder builder = mock(RestTemplateBuilder.class);
|
RestTemplateBuilder builder = mock(RestTemplateBuilder.class);
|
||||||
given(builder.build()).willReturn(delegate);
|
given(builder.build()).willReturn(delegate);
|
||||||
final TestRestTemplate restTemplate = new TestRestTemplate(builder);
|
TestRestTemplate restTemplate = new TestRestTemplate(builder);
|
||||||
ReflectionUtils.doWithMethods(RestOperations.class, new MethodCallback() {
|
ReflectionUtils.doWithMethods(RestOperations.class, new MethodCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,7 +60,6 @@ public class ConfigurationPropertySourcesTests {
|
|||||||
public void attachShouldReAttachInMergedSetup() {
|
public void attachShouldReAttachInMergedSetup() {
|
||||||
ConfigurableEnvironment parent = new StandardEnvironment();
|
ConfigurableEnvironment parent = new StandardEnvironment();
|
||||||
ConfigurationPropertySources.attach(parent);
|
ConfigurationPropertySources.attach(parent);
|
||||||
parent.getProperty("my.example-property");
|
|
||||||
ConfigurableEnvironment child = new StandardEnvironment();
|
ConfigurableEnvironment child = new StandardEnvironment();
|
||||||
child.merge(parent);
|
child.merge(parent);
|
||||||
child.getPropertySources().addLast(new MapPropertySource("config",
|
child.getPropertySources().addLast(new MapPropertySource("config",
|
||||||
|
@ -120,7 +120,7 @@ The following sample applications are provided:
|
|||||||
| Demonstrates JUnit Jupiter-based testing
|
| Demonstrates JUnit Jupiter-based testing
|
||||||
|
|
||||||
| link:spring-boot-sample-kafka[spring-boot-sample-kafka]
|
| link:spring-boot-sample-kafka[spring-boot-sample-kafka]
|
||||||
| consumer and producer using Apache Kafka
|
| Consumer and producer using Apache Kafka
|
||||||
|
|
||||||
| link:spring-boot-sample-liquibase[spring-boot-sample-liquibase]
|
| link:spring-boot-sample-liquibase[spring-boot-sample-liquibase]
|
||||||
| Database migrations with Liquibase
|
| Database migrations with Liquibase
|
||||||
|
@ -2,5 +2,5 @@ spring.kafka.bootstrap-servers=localhost:9092
|
|||||||
spring.kafka.consumer.group-id=testGroup
|
spring.kafka.consumer.group-id=testGroup
|
||||||
spring.kafka.consumer.auto-offset-reset=earliest
|
spring.kafka.consumer.auto-offset-reset=earliest
|
||||||
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
|
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
|
||||||
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
|
|
||||||
spring.kafka.consumer.properties.spring.json.trusted.packages=sample.kafka
|
spring.kafka.consumer.properties.spring.json.trusted.packages=sample.kafka
|
||||||
|
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
|
@ -116,15 +116,14 @@ public class SampleSecureWebFluxCustomSecurityTests {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||||
http.authorizeExchange().matchers(EndpointRequest.to("health", "info"))
|
return http.authorizeExchange().matchers(EndpointRequest.to("health", "info"))
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.matchers(EndpointRequest.toAnyEndpoint()
|
.matchers(EndpointRequest.toAnyEndpoint()
|
||||||
.excluding(MappingsEndpoint.class))
|
.excluding(MappingsEndpoint.class))
|
||||||
.hasRole("ACTUATOR")
|
.hasRole("ACTUATOR")
|
||||||
.matchers(PathRequest.toStaticResources().atCommonLocations())
|
.matchers(PathRequest.toStaticResources().atCommonLocations())
|
||||||
.permitAll().pathMatchers("/login").permitAll().anyExchange()
|
.permitAll().pathMatchers("/login").permitAll().anyExchange()
|
||||||
.authenticated().and().httpBasic();
|
.authenticated().and().httpBasic().and().build();
|
||||||
return http.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user