【发布时间】:2020-05-19 22:31:37
【问题描述】:
enter image description here我只是想建立一个简单的带有休息控制器的弹簧启动应用程序。但无法导入 Rest Controller。这是我的主要方法
package com.test.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
这是我的 build.gradle。该脚本收集类路径上的所有 jar 并构建一个 jar。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-web'
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
有什么想法吗?谢谢
【问题讨论】:
-
什么错误?编译错误?顺便说一句,您通常不会在 SpringBoot 应用程序主类中使用“RestController”。定义一个新类(即 MyRestController),它将定义您的端点
-
如果我在端点中添加错误是“错误:找不到符号@RequestMapping("/")"
标签: spring-boot spring-restcontroller