Upgrade to Spring Boot 2.0.0

This commit upgrades to Spring Boot 2.0.0.

Please note that this commit does not change metrics names to use new
features of Micrometer yet (see gh-526)

Closes gh-611
This commit is contained in:
Stephane Nicoll
2018-02-27 14:43:53 +01:00
parent 5629f95da2
commit fe7650f2c8
29 changed files with 216 additions and 290 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,9 +47,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -70,7 +70,7 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
@Configuration
@EnableConfigurationProperties(InitializrProperties.class)
@AutoConfigureAfter({ CacheAutoConfiguration.class, JacksonAutoConfiguration.class,
WebClientAutoConfiguration.class })
RestTemplateAutoConfiguration.class })
public class InitializrAutoConfiguration {
private final List<ProjectRequestPostProcessor> postProcessors;
@@ -90,9 +90,9 @@ public class InitializrAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public TemplateRenderer templateRenderer(Environment environment) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
"spring.mustache.");
boolean cache = resolver.getProperty("cache", Boolean.class, true);
Binder binder = Binder.get(environment);
boolean cache = binder.bind("spring.mustache.cache", Boolean.class)
.orElseGet(() -> true);
TemplateRenderer templateRenderer = new TemplateRenderer();
templateRenderer.setCache(cache);
return templateRenderer;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,8 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.accept.ContentNegotiationStrategy;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UrlPathHelper;
/**
@@ -39,7 +40,12 @@ import org.springframework.web.util.UrlPathHelper;
*
* @author Stephane Nicoll
*/
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/info", "/actuator/info");
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import java.util.Map;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
/**
@@ -37,7 +37,7 @@ public class LegacyStsController extends AbstractInitializrController {
super(metadataProvider, resourceUrlProvider);
}
@RequestMapping(value = "/sts", produces = "text/html")
@GetMapping(path = "/sts", produces = "text/html")
public String stsHome(Map<String, Object> model) {
renderHome(model);
return "sts-home";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,9 +58,9 @@ import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
@@ -107,18 +107,18 @@ public class MainController extends AbstractInitializrController {
return request;
}
@RequestMapping(value = "/metadata/config", produces = "application/json")
@GetMapping(path = "/metadata/config", produces = "application/json")
@ResponseBody
public InitializrMetadata config() {
return metadataProvider.get();
}
@RequestMapping(value = "/metadata/client")
@GetMapping("/metadata/client")
public String client() {
return "redirect:/";
}
@RequestMapping(value = "/", produces = "text/plain")
@GetMapping(path = "/", produces = "text/plain")
public ResponseEntity<String> serviceCapabilitiesText(
@RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
String appUrl = generateAppUrl();
@@ -150,19 +150,19 @@ public class MainController extends AbstractInitializrController {
return builder.eTag(createUniqueId(content)).body(content);
}
@RequestMapping(value = "/", produces = "application/hal+json")
@GetMapping(path = "/", produces = "application/hal+json")
public ResponseEntity<String> serviceCapabilitiesHal() {
return serviceCapabilitiesFor(InitializrMetadataVersion.V2_1,
HAL_JSON_CONTENT_TYPE);
}
@RequestMapping(value = "/", produces = { "application/vnd.initializr.v2.1+json",
@GetMapping(path = "/", produces = { "application/vnd.initializr.v2.1+json",
"application/json" })
public ResponseEntity<String> serviceCapabilitiesV21() {
return serviceCapabilitiesFor(InitializrMetadataVersion.V2_1);
}
@RequestMapping(value = "/", produces = "application/vnd.initializr.v2+json")
@GetMapping(path = "/", produces = "application/vnd.initializr.v2+json")
public ResponseEntity<String> serviceCapabilitiesV2() {
return serviceCapabilitiesFor(InitializrMetadataVersion.V2);
}
@@ -190,7 +190,7 @@ public class MainController extends AbstractInitializrController {
}
}
@RequestMapping(value = "/dependencies", produces = {
@GetMapping(path = "/dependencies", produces = {
"application/vnd.initializr.v2.1+json", "application/json" })
public ResponseEntity<String> dependenciesV21(
@RequestParam(required = false) String bootVersion) {
@@ -215,25 +215,25 @@ public class MainController extends AbstractInitializrController {
return (frag, out) -> out.write(this.getLinkTo().apply(frag.execute()));
}
@RequestMapping(value = "/", produces = "text/html")
@GetMapping(path = "/", produces = "text/html")
public String home(Map<String, Object> model) {
renderHome(model);
return "home";
}
@RequestMapping("/spring")
@GetMapping(path = { "/spring", "/spring.zip" })
public String spring() {
String url = metadataProvider.get().createCliDistributionURl("zip");
return "redirect:" + url;
}
@RequestMapping(value = { "/spring.tar.gz", "spring.tgz" })
@GetMapping(path = { "/spring.tar.gz", "spring.tgz" })
public String springTgz() {
String url = metadataProvider.get().createCliDistributionURl("tar.gz");
return "redirect:" + url;
}
@RequestMapping("/pom")
@GetMapping(path = { "/pom", "/pom.xml" })
@ResponseBody
public ResponseEntity<byte[]> pom(BasicProjectRequest request) {
request.setType("maven-build");
@@ -241,7 +241,7 @@ public class MainController extends AbstractInitializrController {
return createResponseEntity(mavenPom, "application/octet-stream", "pom.xml");
}
@RequestMapping("/build")
@GetMapping(path = { "/build", "/build.gradle" })
@ResponseBody
public ResponseEntity<byte[]> gradle(BasicProjectRequest request) {
request.setType("gradle-build");
@@ -251,7 +251,7 @@ public class MainController extends AbstractInitializrController {
"build.gradle");
}
@RequestMapping("/starter.zip")
@GetMapping("/starter.zip")
@ResponseBody
public ResponseEntity<byte[]> springZip(BasicProjectRequest basicRequest)
throws IOException {
@@ -282,7 +282,7 @@ public class MainController extends AbstractInitializrController {
return upload(download, dir, generateFileName(request, "zip"), "application/zip");
}
@RequestMapping(value = "/starter.tgz", produces = "application/x-compress")
@GetMapping(path = "/starter.tgz", produces = "application/x-compress")
@ResponseBody
public ResponseEntity<byte[]> springTgz(BasicProjectRequest basicRequest)
throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -51,7 +51,7 @@ public class UiController {
this.metadataProvider = metadataProvider;
}
@RequestMapping(value = "/ui/dependencies", produces = "application/json")
@GetMapping(path = "/ui/dependencies", produces = "application/json")
public ResponseEntity<String> dependencies(
@RequestParam(required = false) String version) {
List<DependencyGroup> dependencyGroups = metadataProvider.get()

View File

@@ -146,7 +146,7 @@ $(function () {
$("#starters div[data-id='" + id + "']").remove();
};
var initializeSearchEngine = function (engine, bootVersion) {
$.getJSON("/ui/dependencies.json?version=" + bootVersion, function (data) {
$.getJSON("/ui/dependencies?version=" + bootVersion, function (data) {
engine.clear();
$.each(data.dependencies, function(idx, item) {
if(item.weight === undefined) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,8 @@ package io.spring.initializr.web;
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import org.junit.runner.RunWith;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,16 +17,14 @@
package io.spring.initializr.web.autoconfigure;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.web.client.RestTemplateCustomizer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.ResponseErrorHandler;
@@ -42,37 +40,23 @@ import static org.mockito.Mockito.mock;
*/
public class InitializrAutoConfigurationTests {
private ConfigurableApplicationContext context;
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(RestTemplateAutoConfiguration.class,
JacksonAutoConfiguration.class,
InitializrAutoConfiguration.class));
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void customRestTemplateBuilderIsUsed() {
load(CustomRestTemplateConfiguration.class);
assertThat(this.context.getBeansOfType(InitializrMetadataProvider.class))
.hasSize(1);
RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
this.context.getBean(InitializrMetadataProvider.class))
.getPropertyValue("restTemplate");
assertThat(restTemplate.getErrorHandler()).isSameAs(
CustomRestTemplateConfiguration.errorHandler);
}
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
if (config != null) {
ctx.register(config);
}
ctx.register(WebClientAutoConfiguration.class, JacksonAutoConfiguration.class,
InitializrAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
this.contextRunner.withUserConfiguration(CustomRestTemplateConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(InitializrMetadataProvider.class);
RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
context.getBean(InitializrMetadataProvider.class))
.getPropertyValue("restTemplate");
assertThat(restTemplate.getErrorHandler()).isSameAs(
CustomRestTemplateConfiguration.errorHandler);
});
}
@Configuration
@@ -84,6 +68,7 @@ public class InitializrAutoConfigurationTests {
public RestTemplateCustomizer testRestTemplateCustomizer() {
return b -> b.setErrorHandler(errorHandler);
}
}
}

View File

@@ -29,6 +29,7 @@ import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
@@ -59,14 +60,13 @@ public class ProjectGenerationSmokeTests
Boolean.getBoolean("smoke.test"));
downloadDir = folder.newFolder();
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList", 2);
fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
fxProfile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/zip,application/x-compress,application/octet-stream");
driver = new FirefoxDriver(fxProfile);
FirefoxOptions options = new FirefoxOptions().setProfile(fxProfile);
driver = new FirefoxDriver(options);
Actions actions = new Actions(driver);
enterAction = actions.sendKeys(Keys.ENTER).build();