Restructure spring-boot-docs packages

Restructure the packages in `spring-boot-docs` so that they mirror
the documentation sections. There are now three main packages:
`springbootfeatures`, `productionreadyfeatures` and `howto`. Each
of the main packages has a subpackage named after the section headings.

Example code now uses consistent `// tag::` names and imports are
applied using `[tag=*]` whenever possible.

Test snippets have been moved to `src/main/java` so that only a single
import attribute needs to be defined.

Closes gh-25089
This commit is contained in:
Phillip Webb
2021-02-02 11:20:32 -08:00
parent db781a0d84
commit 91ccc23462
129 changed files with 1540 additions and 283 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.actuate.metrics;
package org.springframework.boot.docs.howto.actuator;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
@@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
*/
public class MetricsHealthMicrometerExportExample {
// tag::configuration[]
// tag::code[]
@Configuration
public class HealthMetricsConfiguration {
@@ -55,6 +55,6 @@ public class MetricsHealthMicrometerExportExample {
}
}
// end::configuration[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Actuator" section.
*/
package org.springframework.boot.docs.howto.actuator;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Batch Applications" section.
*/
package org.springframework.boot.docs.howto.batchapplications;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Build" section.
*/
package org.springframework.boot.docs.howto.build;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jdbc;
package org.springframework.boot.docs.howto.dataaccess;
import javax.sql.DataSource;
@@ -36,13 +36,13 @@ public class BasicDataSourceExample {
@Configuration(proxyBeanMethods = false)
public static class BasicDataSourceConfiguration {
// tag::configuration[]
// tag::code[]
@Bean
@ConfigurationProperties("app.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jpa;
package org.springframework.boot.docs.howto.dataaccess;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
@@ -29,7 +29,7 @@ import org.springframework.context.annotation.Bean;
*/
class CaseSensitiveSpringPhysicalNamingStrategyExample {
// tag::naming-strategy[]
// tag::code[]
@Bean
SpringPhysicalNamingStrategy caseSensitivePhysicalNamingStrategy() {
return new SpringPhysicalNamingStrategy() {
@@ -41,6 +41,6 @@ class CaseSensitiveSpringPhysicalNamingStrategyExample {
};
}
// end::naming-strategy[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jdbc;
package org.springframework.boot.docs.howto.dataaccess;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.dbcp2.BasicDataSource;
@@ -39,7 +39,7 @@ public class CompleteTwoDataSourcesExample {
@Configuration
public static class CompleteDataSourcesConfiguration {
// tag::configuration[]
// tag::code[]
@Bean
@Primary
@ConfigurationProperties("app.datasource.first")
@@ -65,7 +65,7 @@ public class CompleteTwoDataSourcesExample {
public BasicDataSource secondDataSource() {
return secondDataSourceProperties().initializeDataSourceBuilder().type(BasicDataSource.class).build();
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jdbc;
package org.springframework.boot.docs.howto.dataaccess;
import javax.sql.DataSource;
@@ -40,7 +40,7 @@ public class ConfigurableDataSourceExample {
@Configuration(proxyBeanMethods = false)
public static class ConfigurableDataSourceConfiguration {
// tag::configuration[]
// tag::code[]
@Bean
@Primary
@ConfigurationProperties("app.datasource")
@@ -53,7 +53,7 @@ public class ConfigurableDataSourceExample {
public HikariDataSource dataSource(DataSourceProperties properties) {
return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.elasticsearch;
package org.springframework.boot.docs.howto.dataaccess;
import javax.persistence.EntityManagerFactory;
@@ -29,7 +29,7 @@ import org.springframework.stereotype.Component;
*/
public class HibernateSearchElasticsearchExample {
// tag::configuration[]
// tag::code[]
/**
* {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that
* {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean.
@@ -43,6 +43,6 @@ public class HibernateSearchElasticsearchExample {
}
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jpa;
package org.springframework.boot.docs.howto.dataaccess;
import org.hibernate.cache.jcache.ConfigSettings;
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration;
*
* @author Stephane Nicoll
*/
// tag::configuration[]
// tag::code[]
@Configuration(proxyBeanMethods = false)
public class HibernateSecondLevelCacheExample {
@@ -38,4 +38,4 @@ public class HibernateSecondLevelCacheExample {
}
}
// end::configuration[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.r2dbc;
package org.springframework.boot.docs.howto.dataaccess;
import io.r2dbc.spi.ConnectionFactory;
@@ -32,7 +32,7 @@ import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator;
*/
public class R2dbcDatabaseInitializationExample {
// tag::configuration[]
// tag::code[]
@Configuration(proxyBeanMethods = false)
static class DatabaseInitializationConfiguration {
@@ -45,6 +45,6 @@ public class R2dbcDatabaseInitializationExample {
}
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jdbc;
package org.springframework.boot.docs.howto.dataaccess;
import javax.sql.DataSource;
@@ -38,13 +38,13 @@ public class SimpleDataSourceExample {
@Configuration(proxyBeanMethods = false)
public static class SimpleDataSourceConfiguration {
// tag::configuration[]
// tag::code[]
@Bean
@ConfigurationProperties("app.datasource")
public HikariDataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jdbc;
package org.springframework.boot.docs.howto.dataaccess;
import javax.sql.DataSource;
@@ -42,7 +42,7 @@ public class SimpleTwoDataSourcesExample {
@Configuration
public static class SimpleDataSourcesConfiguration {
// tag::configuration[]
// tag::code[]
@Bean
@Primary
@ConfigurationProperties("app.datasource.first")
@@ -62,7 +62,7 @@ public class SimpleTwoDataSourcesExample {
public BasicDataSource secondDataSource() {
return DataSourceBuilder.create().type(BasicDataSource.class).build();
}
// end::configuration[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Data Access" section.
*/
package org.springframework.boot.docs.howto.dataaccess;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Database Initialization" section.
*/
package org.springframework.boot.docs.howto.databaseinitialization;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.embedded;
package org.springframework.boot.docs.howto.embeddedwebservers;
import org.apache.tomcat.util.http.LegacyCookieProcessor;
@@ -36,13 +36,13 @@ public class TomcatLegacyCookieProcessorExample {
@Configuration(proxyBeanMethods = false)
public static class LegacyCookieProcessorConfiguration {
// tag::customizer[]
// tag::code[]
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return (factory) -> factory
.addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor()));
}
// end::customizer[]
// end::code[]
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.embedded;
package org.springframework.boot.docs.howto.embeddedwebservers;
import java.io.IOException;
import java.net.URL;
@@ -36,7 +36,7 @@ import org.springframework.util.ResourceUtils;
@Configuration(proxyBeanMethods = false)
public class TomcatMultipleConnectorsExample {
// tag::configuration[]
// tag::code[]
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> sslConnectorCustomizer() {
return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createSslConnector());
@@ -63,6 +63,6 @@ public class TomcatMultipleConnectorsExample {
throw new IllegalStateException("Fail to create ssl connector", ex);
}
}
// end::configuration[]
// end::code[]
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.embedded;
package org.springframework.boot.docs.howto.embeddedwebservers;
import io.undertow.Undertow.Builder;
@@ -32,7 +32,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class UndertowMultipleListenersExample {
// tag::configuration[]
// tag::code[]
@Bean
public WebServerFactoryCustomizer<UndertowServletWebServerFactory> undertowListenerCustomizer() {
return (factory) -> {
@@ -46,6 +46,6 @@ public class UndertowMultipleListenersExample {
});
};
}
// end::configuration[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Embedded Web Servers" section.
*/
package org.springframework.boot.docs.howto.embeddedwebservers;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Hot Swapping" section.
*/
package org.springframework.boot.docs.howto.hotswapping;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.web.reactive.function.client;
package org.springframework.boot.docs.howto.httpclients;
import io.netty.channel.ChannelOption;
import io.netty.handler.timeout.ReadTimeoutHandler;
@@ -35,7 +35,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@Configuration(proxyBeanMethods = false)
public class ReactorNettyClientCustomizationExample {
// tag::custom-http-connector[]
// tag::code[]
@Bean
ClientHttpConnector clientHttpConnector(ReactorResourceFactory resourceFactory) {
HttpClient httpClient = HttpClient.create(resourceFactory.getConnectionProvider())
@@ -43,6 +43,6 @@ public class ReactorNettyClientCustomizationExample {
.doOnConnected((connection) -> connection.addHandlerLast(new ReadTimeoutHandler(60)));
return new ReactorClientHttpConnector(httpClient);
}
// end::custom-http-connector[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - HTTP Clients" section.
*/
package org.springframework.boot.docs.howto.httpclients;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.jersey;
package org.springframework.boot.docs.howto.jersey;
import java.util.Collections;
@@ -33,7 +33,7 @@ import org.springframework.stereotype.Component;
*/
public class JerseySetStatusOverSendErrorExample {
// tag::resource-config[]
// tag::code[]
@Component
public class JerseyConfig extends ResourceConfig {
@@ -43,7 +43,7 @@ public class JerseySetStatusOverSendErrorExample {
}
}
// end::resource-config[]
// end::code[]
static class Endpoint {

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Jersey" section.
*/
package org.springframework.boot.docs.howto.jersey;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Logging" section.
*/
package org.springframework.boot.docs.howto.logging;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Messaging" section.
*/
package org.springframework.boot.docs.howto.messaging;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Properties and Configuration" section.
*/
package org.springframework.boot.docs.howto.propertiesandconfiguration;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Security" section.
*/
package org.springframework.boot.docs.howto.security;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context;
package org.springframework.boot.docs.howto.springbootapplication;
import java.io.IOException;
@@ -25,13 +25,14 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
/**
* An {@link EnvironmentPostProcessor} example that loads a YAML file.
*
* @author Stephane Nicoll
*/
// tag::example[]
// tag::code[]
public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor {
private final YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
@@ -44,9 +45,7 @@ public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor
}
private PropertySource<?> loadYaml(Resource path) {
if (!path.exists()) {
throw new IllegalArgumentException("Resource " + path + " does not exist");
}
Assert.isTrue(path.exists(), () -> "Resource " + path + " does not exist");
try {
return this.loader.load("custom-resource", path).get(0);
}
@@ -56,4 +55,4 @@ public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor
}
}
// end::example[]
// end::code[]

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Spring Boot Application" section.
*/
package org.springframework.boot.docs.howto.springbootapplication;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Spring MVC" section.
*/
package org.springframework.boot.docs.howto.springmvc;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Testing with Spring Security" section.
*/
package org.springframework.boot.docs.howto.testingwithspringsecurity;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "How-to - Traditional Deployment" section.
*/
package org.springframework.boot.docs.howto.traditionaldeployment;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Auditing" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.auditing;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.cloudfoundry;
package org.springframework.boot.docs.productionreadyfeatures.cloudfoundry;
import java.io.IOException;
import java.util.Collections;
@@ -44,7 +44,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class CloudFoundryCustomContextPathExample {
// tag::configuration[]
// tag::code[]
@Bean
public TomcatServletWebServerFactory servletWebServerFactory() {
return new TomcatServletWebServerFactory() {
@@ -78,6 +78,6 @@ public class CloudFoundryCustomContextPathExample {
context.addServlet("cloudfoundry", servlet).addMapping("/*");
};
}
// end::configuration[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Cloud Foundry Support" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.cloudfoundry;

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Enabling Production Ready Features"
* section.
*/
package org.springframework.boot.docs.productionreadyfeatures.enabling;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.actuate.endpoint;
package org.springframework.boot.docs.productionreadyfeatures.endpoints;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
@@ -53,6 +53,14 @@ public class CustomEndpointExample {
this.counter = counter;
}
public String getName() {
return this.name;
}
public int getCounter() {
return this.counter;
}
}
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Endpoints" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.endpoints;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - HTTP Tracing" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.httptracing;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Loggers" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.loggers;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.actuate.metrics;
package org.springframework.boot.docs.productionreadyfeatures.metrics;
import io.micrometer.core.instrument.config.MeterFilter;
@@ -31,12 +31,12 @@ public class MetricsFilterBeanExample {
@Configuration(proxyBeanMethods = false)
public static class MetricsFilterExampleConfiguration {
// tag::configuration[]
// tag::code[]
@Bean
public MeterFilter renameRegionTagMeterFilter() {
return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area");
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.actuate.metrics;
package org.springframework.boot.docs.productionreadyfeatures.metrics;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -29,7 +29,7 @@ import io.micrometer.core.instrument.Tags;
*/
public class MetricsMeterRegistryInjectionExample {
// tag::component[]
// tag::code[]
class Dictionary {
private final List<String> words = new CopyOnWriteArrayList<>();
@@ -38,9 +38,9 @@ public class MetricsMeterRegistryInjectionExample {
registry.gaugeCollectionSize("dictionary.size", Tags.empty(), this.words);
}
//
// ...
}
// end::component[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.actuate.metrics;
package org.springframework.boot.docs.productionreadyfeatures.metrics;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.binder.MeterBinder;
@@ -28,12 +28,12 @@ import org.springframework.context.annotation.Bean;
*/
public class SampleMeterBinderConfiguration {
// tag::example[]
// tag::code[]
@Bean
MeterBinder queueSize(Queue queue) {
return (registry) -> Gauge.builder("queueSize", queue::size).register(registry);
}
// end::example[]
// end::code[]
static class Queue {

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Metrics" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.metrics;

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Monitoring and Management overt HTTP"
* section.
*/
package org.springframework.boot.docs.productionreadyfeatures.monitoring.http;

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Monitoring and Management overt JMX"
* section.
*/
package org.springframework.boot.docs.productionreadyfeatures.monitoring.jmx;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Production Ready Features - Process Monitoring" section.
*/
package org.springframework.boot.docs.productionreadyfeatures.processmonitoring;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Caching" section.
*/
package org.springframework.boot.docs.springbootfeatures.caching;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Container Images" section.
*/
package org.springframework.boot.docs.springbootfeatures.containerimages;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.autoconfigure;
package org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration;
/**
* Sample service.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.docs.autoconfigure;
package org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.docs.autoconfigure.UserServiceAutoConfiguration.UserProperties;
import org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration.UserServiceAutoConfiguration.UserProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Creating Your Own Auto-Configuration" section.
*/
package org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Sending Email" section.
*/
package org.springframework.boot.docs.springbootfeatures.email;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.properties.bind.constructor;
package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.datasize.constructorbinding;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
@@ -29,7 +29,7 @@ import org.springframework.util.unit.DataUnit;
*
* @author Stephane Nicoll
*/
// tag::example[]
// tag::code[]
@ConfigurationProperties("app.io")
@ConstructorBinding
public class AppIoProperties {
@@ -53,4 +53,4 @@ public class AppIoProperties {
}
}
// end::example[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.properties.bind.javabean;
package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.datasize.javabeanbinding;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DataSizeUnit;
@@ -27,7 +27,7 @@ import org.springframework.util.unit.DataUnit;
*
* @author Stephane Nicoll
*/
// tag::example[]
// tag::code[]
@ConfigurationProperties("app.io")
public class AppIoProperties {
@@ -53,4 +53,4 @@ public class AppIoProperties {
}
}
// end::example[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.properties.bind.constructor;
package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.constructorbinding;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
@@ -30,7 +30,7 @@ import org.springframework.boot.convert.DurationUnit;
*
* @author Stephane Nicoll
*/
// tag::example[]
// tag::code[]
@ConfigurationProperties("app.system")
@ConstructorBinding
public class AppSystemProperties {
@@ -54,4 +54,4 @@ public class AppSystemProperties {
}
}
// end::example[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.context.properties.bind.javabean;
package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.javabeanbinding;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
@@ -28,7 +28,7 @@ import org.springframework.boot.convert.DurationUnit;
*
* @author Stephane Nicoll
*/
// tag::example[]
// tag::code[]
@ConfigurationProperties("app.system")
public class AppSystemProperties {
@@ -54,4 +54,4 @@ public class AppSystemProperties {
}
}
// end::example[]
// end::code[]

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Externalized Configuration" section.
*/
package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Graceful Shutdown" section.
*/
package org.springframework.boot.docs.springbootfeatures.gracefulshutdown;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Hazelcast" section.
*/
package org.springframework.boot.docs.springbootfeatures.hazelcast;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Spring Integration" section.
*/
package org.springframework.boot.docs.springbootfeatures.integration;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Internationalization" section.
*/
package org.springframework.boot.docs.springbootfeatures.internationalization;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - JSON" section.
*/
package org.springframework.boot.docs.springbootfeatures.json;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Distributed Transactions with JTA" section.
*/
package org.springframework.boot.docs.springbootfeatures.jta;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Kotlin" section.
*/
package org.springframework.boot.docs.springbootfeatures.kotlin;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Logging" section.
*/
package org.springframework.boot.docs.springbootfeatures.logging;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.kafka;
package org.springframework.boot.docs.springbootfeatures.messaging;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.KeyValue;
@@ -34,7 +34,7 @@ import org.springframework.kafka.support.serializer.JsonSerde;
*/
public class KafkaStreamsBeanExample {
// tag::configuration[]
// tag::code[]
@Configuration(proxyBeanMethods = false)
@EnableKafkaStreams
public static class KafkaStreamsExampleConfiguration {
@@ -48,6 +48,6 @@ public class KafkaStreamsBeanExample {
}
}
// end::configuration[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Messaging" section.
*/
package org.springframework.boot.docs.springbootfeatures.messaging;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Monitoring with JMX" section.
*/
package org.springframework.boot.docs.springbootfeatures.monitoring.jmx;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.cache;
package org.springframework.boot.docs.springbootfeatures.nosql;
import java.time.Duration;
@@ -32,7 +32,7 @@ import org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration;
@Configuration(proxyBeanMethods = false)
public class CouchbaseCacheManagerCustomizationExample {
// tag::configuration[]
// tag::code[]
@Bean
public CouchbaseCacheManagerBuilderCustomizer myCouchbaseCacheManagerBuilderCustomizer() {
return (builder) -> builder
@@ -42,6 +42,6 @@ public class CouchbaseCacheManagerCustomizationExample {
CouchbaseCacheConfiguration.defaultCacheConfig().entryExpiry(Duration.ofMinutes(1)));
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.neo4j;
package org.springframework.boot.docs.springbootfeatures.nosql;
import org.neo4j.driver.Driver;
@@ -32,12 +32,12 @@ import org.springframework.transaction.ReactiveTransactionManager;
@Configuration(proxyBeanMethods = false)
public class Neo4jReactiveTransactionManagerExample {
// tag::configuration[]
// tag::code[]
@Bean
public ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver,
ReactiveDatabaseSelectionProvider databaseNameProvider) {
return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider);
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.cache;
package org.springframework.boot.docs.springbootfeatures.nosql;
import java.time.Duration;
@@ -32,7 +32,7 @@ import org.springframework.data.redis.cache.RedisCacheConfiguration;
@Configuration(proxyBeanMethods = false)
public class RedisCacheManagerCustomizationExample {
// tag::configuration[]
// tag::code[]
@Bean
public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() {
return (builder) -> builder
@@ -42,6 +42,6 @@ public class RedisCacheManagerCustomizationExample {
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(1)));
}
// end::configuration[]
// end::code[]
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Working with NoSQL Technologies" section.
*/
package org.springframework.boot.docs.springbootfeatures.nosql;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Profiles" section.
*/
package org.springframework.boot.docs.springbootfeatures.profiles;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Quartz" section.
*/
package org.springframework.boot.docs.springbootfeatures.quartz;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.web.client;
package org.springframework.boot.docs.springbootfeatures.resttemplate;
import java.time.Duration;
@@ -32,12 +32,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class RestTemplateBuilderCustomizationExample {
// tag::customizer[]
// tag::code[]
@Bean
public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer configurer) {
return configurer.configure(new RestTemplateBuilder()).setConnectTimeout(Duration.ofSeconds(5))
.setReadTimeout(Duration.ofSeconds(2));
}
// end::customizer[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.web.client;
package org.springframework.boot.docs.springbootfeatures.resttemplate;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
@@ -39,7 +39,7 @@ public class RestTemplateProxyCustomizationExample {
* A {@link RestTemplateCustomizer} that applies an HttpComponents-based request
* factory that is configured to use a proxy.
*/
// tag::customizer[]
// tag::code[]
static class ProxyCustomizer implements RestTemplateCustomizer {
@Override
@@ -61,6 +61,6 @@ public class RestTemplateProxyCustomizationExample {
}
}
// end::customizer[]
// end::code[]
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Calling REST Services with RestTemplate"
* section.
*/
package org.springframework.boot.docs.springbootfeatures.resttemplate;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - RSocket" section.
*/
package org.springframework.boot.docs.springbootfeatures.rsocket;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.web.security;
package org.springframework.boot.docs.springbootfeatures.security;
import org.springframework.boot.autoconfigure.security.reactive.PathRequest;
import org.springframework.context.annotation.Bean;
@@ -31,7 +31,7 @@ import org.springframework.security.web.server.SecurityWebFilterChain;
public class CustomWebFluxSecurityExample {
// @formatter:off
// tag::configuration[]
// tag::code[]
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
return http
@@ -42,7 +42,7 @@ public class CustomWebFluxSecurityExample {
.formLogin().and()
.build();
}
// end::configuration[]
// end::code[]
// @formatter:on
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Security" section.
*/
package org.springframework.boot.docs.springbootfeatures.security;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Spring Session" section.
*/
package org.springframework.boot.docs.springbootfeatures.session;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs;
package org.springframework.boot.docs.springbootfeatures.springapplication;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
@@ -26,9 +26,9 @@ import org.springframework.context.annotation.Bean;
*
* @author Stephane Nicoll
*/
// tag::example[]
// tag::code[]
@SpringBootApplication
public class ExitCodeApplication {
public class ExitCodeExample {
@Bean
public ExitCodeGenerator exitCodeGenerator() {
@@ -36,8 +36,8 @@ public class ExitCodeApplication {
}
public static void main(String[] args) {
System.exit(SpringApplication.exit(SpringApplication.run(ExitCodeApplication.class, args)));
System.exit(SpringApplication.exit(SpringApplication.run(ExitCodeExample.class, args)));
}
}
// end::example[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.builder;
package org.springframework.boot.docs.springbootfeatures.springapplication;
import org.springframework.boot.Banner;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -28,13 +28,13 @@ public class SpringApplicationBuilderExample {
public void hierarchyWithDisabledBanner(String[] args) {
// @formatter:off
// tag::hierarchy[]
// tag::code[]
new SpringApplicationBuilder()
.sources(Parent.class)
.child(Application.class)
.bannerMode(Banner.Mode.OFF)
.run(args);
// end::hierarchy[]
// end::code[]
// @formatter:on
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - SpringApplication" section.
*/
package org.springframework.boot.docs.springbootfeatures.springapplication;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Working with SQL Databases" section.
*/
package org.springframework.boot.docs.springbootfeatures.sql;

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Task Execution and Scheduling" section.
*/
package org.springframework.boot.docs.springbootfeatures.task;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.context;
package org.springframework.boot.docs.springbootfeatures.testing;
import org.junit.jupiter.api.Test;
@@ -24,7 +24,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import static org.assertj.core.api.Assertions.assertThat;
// tag::example[]
// tag::code[]
@SpringBootTest(args = "--app.test=one")
class ApplicationArgumentsExampleTests {
@@ -35,4 +35,4 @@ class ApplicationArgumentsExampleTests {
}
}
// end::example[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.web;
package org.springframework.boot.docs.springbootfeatures.testing;
// tag::test-mock-mvc[]
// tag::code[]
import org.junit.jupiter.api.Test;
@@ -39,4 +39,4 @@ class MockMvcExampleTests {
}
}
// end::test-mock-mvc[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.web;
package org.springframework.boot.docs.springbootfeatures.testing;
// tag::test-mock-web-test-client[]
// tag::code[]
import org.junit.jupiter.api.Test;
@@ -35,4 +35,4 @@ class MockWebTestClientExampleTests {
}
}
// end::test-mock-web-test-client[]
// end::code[]

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.springbootfeatures.testing;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Sample showcasing the use of {@link CapturedOutput}.
*
* @author Stephane Nicoll
*/
// tag::code[]
@ExtendWith(OutputCaptureExtension.class)
class OutputCaptureTests {
@Test
void testName(CapturedOutput output) {
System.out.println("Hello World!");
assertThat(output).contains("World");
}
}
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.web;
package org.springframework.boot.docs.springbootfeatures.testing;
// tag::test-random-port[]
// tag::code[]
import org.junit.jupiter.api.Test;
@@ -37,4 +37,4 @@ class RandomPortTestRestTemplateExampleTests {
}
}
// end::test-random-port[]
// end::code[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.web;
package org.springframework.boot.docs.springbootfeatures.testing;
// tag::test-random-port[]
// tag::code[]
import org.junit.jupiter.api.Test;
@@ -34,4 +34,4 @@ class RandomPortWebTestClientExampleTests {
}
}
// end::test-random-port[]
// end::code[]

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.springbootfeatures.testing;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration.UserService;
import org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration.UserServiceAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link UserServiceAutoConfiguration}.
*
* @author Stephane Nicoll
*/
class UserServiceAutoConfigurationTests {
// tag::runner[]
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(UserServiceAutoConfiguration.class));
// end::runner[]
// tag::test-env[]
@Test
void serviceNameCanBeConfigured() {
this.contextRunner.withPropertyValues("user.name=test123").run((context) -> {
assertThat(context).hasSingleBean(UserService.class);
assertThat(context.getBean(UserService.class).getName()).isEqualTo("test123");
});
}
// end::test-env[]
// tag::test-classloader[]
@Test
void serviceIsIgnoredIfLibraryIsNotPresent() {
this.contextRunner.withClassLoader(new FilteredClassLoader(UserService.class))
.run((context) -> assertThat(context).doesNotHaveBean("userService"));
}
// end::test-classloader[]
// tag::test-user-config[]
@Test
void defaultServiceBacksOff() {
this.contextRunner.withUserConfiguration(UserConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(UserService.class);
assertThat(context).getBean("myUserService").isSameAs(context.getBean(UserService.class));
});
}
@Configuration(proxyBeanMethods = false)
static class UserConfiguration {
@Bean
UserService myUserService() {
return new UserService("mine");
}
}
// end::test-user-config[]
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.springbootfeatures.testing.jmx;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
/**
* A sample {@link SpringBootConfiguration @ConfigurationProperties} that only enables JMX
* auto-configuration.
*
* @author Stephane Nicoll
*/
@SpringBootConfiguration
@ImportAutoConfiguration(JmxAutoConfiguration.class)
public class SampleApp {
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.springbootfeatures.testing.jmx;
import javax.management.MBeanServer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Example integration test that uses JMX.
*
* @author Stephane Nicoll
*/
@SuppressWarnings("unused")
// tag::code[]
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = "spring.jmx.enabled=true")
@DirtiesContext
class SampleJmxTests {
@Autowired
private MBeanServer mBeanServer;
@Test
void exampleTest() {
// ...
}
}
// end::code[]

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Examples for the "Spring Boot Features - Testing" section.
*/
package org.springframework.boot.docs.springbootfeatures.testing;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.autoconfigure.restdocs.restassured;
package org.springframework.boot.docs.springbootfeatures.testing.restdocs.restassured;
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsRestAssuredConfigurationCustomizer;
import org.springframework.boot.test.context.TestConfiguration;
@@ -23,7 +23,7 @@ import org.springframework.restdocs.templates.TemplateFormats;
public class AdvancedConfigurationExample {
// tag::configuration[]
// tag::code[]
@TestConfiguration(proxyBeanMethods = false)
public static class CustomizationConfiguration implements RestDocsRestAssuredConfigurationCustomizer {
@@ -33,6 +33,6 @@ public class AdvancedConfigurationExample {
}
}
// end::configuration[]
// end::code[]
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot.docs.test.autoconfigure.restdocs.restassured;
package org.springframework.boot.docs.springbootfeatures.testing.restdocs.restassured;
// tag::source[]
// tag::code[]
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -41,4 +41,4 @@ class UserDocumentationTests {
}
}
// end::source[]
// end::code[]

Some files were not shown because too many files have changed in this diff Show More