Merge branch '2.0.x' into 2.1.x

Closes gh-17078
This commit is contained in:
Andy Wilkinson
2019-06-07 10:50:34 +01:00
2691 changed files with 27746 additions and 46049 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -36,8 +36,7 @@ public class ExitCodeApplication {
}
public static void main(String[] args) {
System.exit(SpringApplication
.exit(SpringApplication.run(ExitCodeApplication.class, args)));
System.exit(SpringApplication.exit(SpringApplication.run(ExitCodeApplication.class, args)));
}
}

View File

@@ -50,14 +50,12 @@ public class CloudFoundryCustomContextPathExample {
return new TomcatServletWebServerFactory() {
@Override
protected void prepareContext(Host host,
ServletContextInitializer[] initializers) {
protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
super.prepareContext(host, initializers);
StandardContext child = new StandardContext();
child.addLifecycleListener(new Tomcat.FixContextListener());
child.setPath("/cloudfoundryapplication");
ServletContainerInitializer initializer = getServletContextInitializer(
getContextPath());
ServletContainerInitializer initializer = getServletContextInitializer(getContextPath());
child.addServletContainerInitializer(initializer, Collections.emptySet());
child.setCrossContext(true);
host.addChild(child);
@@ -71,12 +69,9 @@ public class CloudFoundryCustomContextPathExample {
Servlet servlet = new GenericServlet() {
@Override
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
ServletContext context = req.getServletContext()
.getContext(contextPath);
context.getRequestDispatcher("/cloudfoundryapplication").forward(req,
res);
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
ServletContext context = req.getServletContext().getContext(contextPath);
context.getRequestDispatcher("/cloudfoundryapplication").forward(req, res);
}
};

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -37,8 +37,7 @@ public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor
private final YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
Resource path = new ClassPathResource("com/example/myapp/config.yml");
PropertySource<?> propertySource = loadYaml(path);
environment.getPropertySources().addLast(propertySource);
@@ -52,8 +51,7 @@ public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor
return this.loader.load("custom-resource", path).get(0);
}
catch (IOException ex) {
throw new IllegalStateException(
"Failed to load yaml configuration from " + path, ex);
throw new IllegalStateException("Failed to load yaml configuration from " + path, ex);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -39,8 +39,8 @@ public class TomcatLegacyCookieProcessorExample {
// tag::customizer[]
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return (factory) -> factory.addContextCustomizers(
(context) -> context.setCookieProcessor(new LegacyCookieProcessor()));
return (factory) -> factory
.addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor()));
}
// end::customizer[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -35,8 +35,7 @@ public class HibernateSearchElasticsearchExample {
* {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean.
*/
@Configuration
static class ElasticsearchJpaDependencyConfiguration
extends EntityManagerFactoryDependsOnPostProcessor {
static class ElasticsearchJpaDependencyConfiguration extends EntityManagerFactoryDependsOnPostProcessor {
ElasticsearchJpaDependencyConfiguration() {
super("elasticsearchClient");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -51,8 +51,7 @@ public class CompleteTwoDataSourcesExample {
@Primary
@ConfigurationProperties("app.datasource.first.configuration")
public HikariDataSource firstDataSource() {
return firstDataSourceProperties().initializeDataSourceBuilder()
.type(HikariDataSource.class).build();
return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
@Bean
@@ -64,8 +63,7 @@ public class CompleteTwoDataSourcesExample {
@Bean
@ConfigurationProperties("app.datasource.second.configuration")
public BasicDataSource secondDataSource() {
return secondDataSourceProperties().initializeDataSourceBuilder()
.type(BasicDataSource.class).build();
return secondDataSourceProperties().initializeDataSourceBuilder().type(BasicDataSource.class).build();
}
// end::configuration[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -51,8 +51,7 @@ public class ConfigurableDataSourceExample {
@Bean
@ConfigurationProperties("app.datasource.configuration")
public HikariDataSource dataSource(DataSourceProperties properties) {
return properties.initializeDataSourceBuilder().type(HikariDataSource.class)
.build();
return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
// end::configuration[]

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -54,8 +54,7 @@ public class SimpleTwoDataSourcesExample {
@Primary
@ConfigurationProperties("app.datasource.first.configuration")
public HikariDataSource firstDataSource() {
return firstDataSourceProperties().initializeDataSourceBuilder()
.type(HikariDataSource.class).build();
return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
@Bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -39,8 +39,7 @@ public class JerseySetStatusOverSendErrorExample {
public JerseyConfig() {
register(Endpoint.class);
setProperties(Collections.singletonMap(
"jersey.config.server.response.setStatusOverSendError", true));
setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -33,10 +33,8 @@ import org.springframework.context.annotation.Configuration;
public class HibernateSecondLevelCacheExample {
@Bean
public HibernatePropertiesCustomizer hibernateSecondLevelCacheCustomizer(
JCacheCacheManager cacheManager) {
return (properties) -> properties.put(ConfigSettings.CACHE_MANAGER,
cacheManager.getCacheManager());
public HibernatePropertiesCustomizer hibernateSecondLevelCacheCustomizer(JCacheCacheManager cacheManager) {
return (properties) -> properties.put(ConfigSettings.CACHE_MANAGER, cacheManager.getCacheManager());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -25,8 +25,7 @@ public class AdvancedConfigurationExample {
// tag::configuration[]
@TestConfiguration
public static class CustomizationConfiguration
implements RestDocsRestAssuredConfigurationCustomizer {
public static class CustomizationConfiguration implements RestDocsRestAssuredConfigurationCustomizer {
@Override
public void customize(RestAssuredRestDocumentationConfigurer configurer) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -45,8 +45,8 @@ public class UserDocumentationTests {
@Test
public void listUsers() {
given(this.documentationSpec).filter(document("list-users")).when()
.port(this.port).get("/").then().assertThat().statusCode(is(200));
given(this.documentationSpec).filter(document("list-users")).when().port(this.port).get("/").then().assertThat()
.statusCode(is(200));
}
}

View File

@@ -24,8 +24,7 @@ public class AdvancedConfigurationExample {
// tag::configuration[]
@TestConfiguration
public static class CustomizationConfiguration
implements RestDocsWebTestClientConfigurationCustomizer {
public static class CustomizationConfiguration implements RestDocsWebTestClientConfigurationCustomizer {
@Override
public void customize(WebTestClientRestDocumentationConfigurer configurer) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -41,8 +41,7 @@ public class MockMvcExampleTests {
@Test
public void exampleTest() throws Exception {
this.mvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string("Hello World"));
this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -37,8 +37,8 @@ public class MockWebTestClientExampleTests {
@Test
public void exampleTest() {
this.webClient.get().uri("/").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("Hello World");
this.webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class)
.isEqualTo("Hello World");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -36,8 +36,8 @@ public class RandomPortWebTestClientExampleTests {
@Test
public void exampleTest() {
this.webClient.get().uri("/").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("Hello World");
this.webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class)
.isEqualTo("Hello World");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -45,22 +45,19 @@ public class RestTemplateProxyCustomizationExample {
@Override
public void customize(RestTemplate restTemplate) {
HttpHost proxy = new HttpHost("proxy.example.com");
HttpClient httpClient = HttpClientBuilder.create()
.setRoutePlanner(new DefaultProxyRoutePlanner(proxy) {
HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxy) {
@Override
public HttpHost determineProxy(HttpHost target,
HttpRequest request, HttpContext context)
throws HttpException {
if (target.getHostName().equals("192.168.0.5")) {
return null;
}
return super.determineProxy(target, request, context);
}
@Override
public HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context)
throws HttpException {
if (target.getHostName().equals("192.168.0.5")) {
return null;
}
return super.determineProxy(target, request, context);
}
}).build();
restTemplate.setRequestFactory(
new HttpComponentsClientHttpRequestFactory(httpClient));
}).build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -60,12 +60,11 @@ public class UserServiceAutoConfigurationTests {
// tag::test-user-config[]
@Test
public void defaultServiceBacksOff() {
this.contextRunner.withUserConfiguration(UserConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(UserService.class);
assertThat(context.getBean(UserService.class)).isSameAs(
context.getBean(UserConfiguration.class).myUserService());
});
this.contextRunner.withUserConfiguration(UserConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(UserService.class);
assertThat(context.getBean(UserService.class))
.isSameAs(context.getBean(UserConfiguration.class).myUserService());
});
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -35,8 +35,7 @@ public class EnvironmentPostProcessorExampleTests {
@Test
public void applyEnvironmentPostProcessor() {
assertThat(this.environment.containsProperty("test.foo.bar")).isFalse();
new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment,
new SpringApplication());
new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment, new SpringApplication());
assertThat(this.environment.containsProperty("test.foo.bar")).isTrue();
assertThat(this.environment.getProperty("test.foo.bar")).isEqualTo("value");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -42,10 +42,9 @@ public class TomcatLegacyCookieProcessorExampleTests {
public void cookieProcessorIsCustomized() {
ServletWebServerApplicationContext applicationContext = (ServletWebServerApplicationContext) new SpringApplication(
TestConfiguration.class, LegacyCookieProcessorConfiguration.class).run();
Context context = (Context) ((TomcatWebServer) applicationContext.getWebServer())
.getTomcat().getHost().findChildren()[0];
assertThat(context.getCookieProcessor())
.isInstanceOf(LegacyCookieProcessor.class);
Context context = (Context) ((TomcatWebServer) applicationContext.getWebServer()).getTomcat().getHost()
.findChildren()[0];
assertThat(context.getCookieProcessor()).isInstanceOf(LegacyCookieProcessor.class);
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -41,43 +41,32 @@ public class AppSystemPropertiesTests {
@Test
public void bindWithDefaultUnit() {
this.contextRunner
.withPropertyValues("app.system.session-timeout=40",
"app.system.read-timeout=5000")
this.contextRunner.withPropertyValues("app.system.session-timeout=40", "app.system.read-timeout=5000")
.run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout())
.isEqualTo(Duration.ofSeconds(40));
assertThat(properties.getReadTimeout())
.isEqualTo(Duration.ofMillis(5000));
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofSeconds(40));
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(5000));
}));
}
@Test
public void bindWithExplicitUnit() {
this.contextRunner.withPropertyValues("app.system.session-timeout=1h",
"app.system.read-timeout=5s").run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout())
.isEqualTo(Duration.ofMinutes(60));
assertThat(properties.getReadTimeout())
.isEqualTo(Duration.ofMillis(5000));
this.contextRunner.withPropertyValues("app.system.session-timeout=1h", "app.system.read-timeout=5s")
.run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofMinutes(60));
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(5000));
}));
}
@Test
public void bindWithIso8601Format() {
this.contextRunner
.withPropertyValues("app.system.session-timeout=PT15S",
"app.system.read-timeout=PT0.5S")
this.contextRunner.withPropertyValues("app.system.session-timeout=PT15S", "app.system.read-timeout=PT0.5S")
.run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout())
.isEqualTo(Duration.ofSeconds(15));
assertThat(properties.getReadTimeout())
.isEqualTo(Duration.ofMillis(500));
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofSeconds(15));
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(500));
}));
}
private ContextConsumer<AssertableApplicationContext> assertBinding(
Consumer<AppSystemProperties> properties) {
private ContextConsumer<AssertableApplicationContext> assertBinding(Consumer<AppSystemProperties> properties) {
return (context) -> {
assertThat(context).hasSingleBean(AppSystemProperties.class);
properties.accept(context.getBean(AppSystemProperties.class));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -48,8 +48,7 @@ public class BasicDataSourceExampleTests {
public void validateConfiguration() throws SQLException {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(1);
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(dataSource.getConnection().getMetaData().getURL())
.isEqualTo("jdbc:h2:mem:basic");
assertThat(dataSource.getConnection().getMetaData().getURL()).isEqualTo("jdbc:h2:mem:basic");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -49,12 +49,9 @@ public class CompleteTwoDataSourcesExampleTests {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(this.context.getBean("firstDataSource")).isSameAs(dataSource);
assertThat(dataSource.getConnection().getMetaData().getURL())
.startsWith("jdbc:h2:mem:");
DataSource secondDataSource = this.context.getBean("secondDataSource",
DataSource.class);
assertThat(secondDataSource.getConnection().getMetaData().getURL())
.startsWith("jdbc:h2:mem:");
assertThat(dataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
DataSource secondDataSource = this.context.getBean("secondDataSource", DataSource.class);
assertThat(secondDataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
}
}

View File

@@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@SpringBootTest(
properties = { "app.datasource.url=jdbc:h2:mem:configurable;DB_CLOSE_DELAY=-1",
"app.datasource.configuration.maximum-pool-size=42" })
@SpringBootTest(properties = { "app.datasource.url=jdbc:h2:mem:configurable;DB_CLOSE_DELAY=-1",
"app.datasource.configuration.maximum-pool-size=42" })
@Import(ConfigurableDataSourceExample.ConfigurableDataSourceConfiguration.class)
public class ConfigurableDataSourceExampleTests {
@@ -51,8 +50,7 @@ public class ConfigurableDataSourceExampleTests {
public void validateConfiguration() throws SQLException {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(1);
HikariDataSource dataSource = this.context.getBean(HikariDataSource.class);
assertThat(dataSource.getConnection().getMetaData().getURL())
.isEqualTo("jdbc:h2:mem:configurable");
assertThat(dataSource.getConnection().getMetaData().getURL()).isEqualTo("jdbc:h2:mem:configurable");
assertThat(dataSource.getMaximumPoolSize()).isEqualTo(42);
}

View File

@@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@SpringBootTest(
properties = { "app.datasource.jdbc-url=jdbc:h2:mem:simple;DB_CLOSE_DELAY=-1",
"app.datasource.maximum-pool-size=42" })
@SpringBootTest(properties = { "app.datasource.jdbc-url=jdbc:h2:mem:simple;DB_CLOSE_DELAY=-1",
"app.datasource.maximum-pool-size=42" })
@Import(SimpleDataSourceExample.SimpleDataSourceConfiguration.class)
public class SimpleDataSourceExampleTests {
@@ -51,8 +50,7 @@ public class SimpleDataSourceExampleTests {
public void validateConfiguration() throws SQLException {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(1);
HikariDataSource dataSource = this.context.getBean(HikariDataSource.class);
assertThat(dataSource.getConnection().getMetaData().getURL())
.isEqualTo("jdbc:h2:mem:simple");
assertThat(dataSource.getConnection().getMetaData().getURL()).isEqualTo("jdbc:h2:mem:simple");
assertThat(dataSource.getMaximumPoolSize()).isEqualTo(42);
}

View File

@@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@SpringBootTest(
properties = { "app.datasource.second.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1",
"app.datasource.second.max-total=42" })
@SpringBootTest(properties = { "app.datasource.second.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1",
"app.datasource.second.max-total=42" })
@Import(SimpleTwoDataSourcesExample.SimpleDataSourcesConfiguration.class)
public class SimpleTwoDataSourcesExampleTests {
@@ -52,12 +51,9 @@ public class SimpleTwoDataSourcesExampleTests {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(this.context.getBean("firstDataSource")).isSameAs(dataSource);
assertThat(dataSource.getConnection().getMetaData().getURL())
.startsWith("jdbc:h2:mem:");
BasicDataSource secondDataSource = this.context.getBean("secondDataSource",
BasicDataSource.class);
assertThat(secondDataSource.getUrl())
.isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
assertThat(dataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
BasicDataSource secondDataSource = this.context.getBean("secondDataSource", BasicDataSource.class);
assertThat(secondDataSource.getUrl()).isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
assertThat(secondDataSource.getMaxTotal()).isEqualTo(42);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -34,9 +34,8 @@ import org.springframework.web.bind.annotation.RestController;
* @author Stephane Nicoll
*/
@SpringBootConfiguration
@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class,
DispatcherServletAutoConfiguration.class, JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class })
@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class,
JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class })
class SampleWebClientConfiguration {
@RestController
@@ -44,9 +43,7 @@ class SampleWebClientConfiguration {
@RequestMapping("/example")
public ResponseEntity<String> example() {
return ResponseEntity.ok()
.location(URI.create("https://other.example.com/example"))
.body("test");
return ResponseEntity.ok().location(URI.create("https://other.example.com/example")).body("test");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -48,8 +48,7 @@ public class SampleWebClientTests {
@Test
public void testRequest() {
HttpHeaders headers = this.template.getForEntity("/example", String.class)
.getHeaders();
HttpHeaders headers = this.template.getForEntity("/example", String.class).getHeaders();
assertThat(headers.getLocation()).hasHost("other.example.com");
}