diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java index 87116e4333..8558294dcd 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java @@ -51,6 +51,7 @@ public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguratio imports.addStarImports("org.springframework.web.bind.annotation", "org.springframework.web.servlet.config.annotation", "org.springframework.web.servlet", + "org.springframework.http", "org.springframework.web.servlet.handler", "org.springframework.http", "org.springframework.ui", "groovy.text"); imports.addStaticImport(GroovyTemplate.class.getName(), "template"); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java index a08586bbd3..2428dfe6ad 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringTestCompilerAutoConfiguration.java @@ -28,6 +28,7 @@ import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.springframework.boot.cli.compiler.AstUtils; import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; +import org.springframework.boot.cli.compiler.DependencyCustomizer; import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration; /** @@ -44,6 +45,12 @@ public class SpringTestCompilerAutoConfiguration extends CompilerAutoConfigurati "SpringApplicationConfiguration"); } + @Override + public void applyDependencies(DependencyCustomizer dependencies) { + dependencies.ifAnyMissingClasses("org.springframework.http.HttpHeaders").add( + "spring-boot-starter-web"); + } + @Override public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, @@ -58,10 +65,9 @@ public class SpringTestCompilerAutoConfiguration extends CompilerAutoConfigurati @Override public void applyImports(ImportCustomizer imports) throws CompilationFailedException { - imports.addStarImports("org.junit.runner") - .addStarImports("org.springframework.boot.test") - .addStarImports("org.springframework.test.context.junit4") - .addStarImports("org.springframework.test.annotation") - .addImports("org.springframework.test.context.web.WebAppConfiguration"); + imports.addStarImports("org.junit.runner", "org.springframework.boot.test", + "org.springframework.http", "org.springframework.test.context.junit4", + "org.springframework.test.annotation").addImports( + "org.springframework.test.context.web.WebAppConfiguration"); } }