I keep getting this error:
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
This is the target in my run configuration.
package mystuff;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication(scanBasePackages = "mystuff")
public class Runner {
public static void main(String[] args) {
new SpringApplicationBuilder(MyApp.class).run(args);
}
}
And this is MyApp.class:
package mystuff;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyApp {
@RequestMapping("/")
public String index() {
return "Hello World";
}
}
And this is my Gradle build file:
plugins {
java
id("org.springframework.boot") version "2.2.2.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
testCompile("junit", "junit", "4.12")
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
Both MyApp.java and Runner.java are in the same package, "mystuff". I searched around here on Stackoverflow, but my configuration appears to be correct.
In Runner class, replace
new SpringApplicationBuilder(MyApp.class).run(args);
with
new SpringApplicationBuilder(MyApp.class).web(WebApplicationType.SERVLET).run(args);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With