【发布时间】:2020-08-08 14:55:28
【问题描述】:
我不断收到此错误:
原因:org.springframework.context.ApplicationContextException:由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext。
这是我的运行配置中的目标。
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);
}
}
这是 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";
}
}
这是我的 Gradle 构建文件:
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
}
MyApp.java 和 Runner.java 都在同一个包“mystuff”中。我在 Stackoverflow 上搜索了这里,但我的配置似乎是正确的。
【问题讨论】:
标签: spring spring-boot