为什么我不能导入@RestController spring boot

问题描述 投票:0回答:1

enter image description here我只是想建立一个具有rest控制器的简单spring boot应用程序。但是无法导入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")
}

有什么想法吗?谢谢

spring-boot spring-restcontroller
1个回答
0
投票

您缺少@RequestMapping("/")的导入。

import org.springframework.web.bind.annotation.RequestMapping;
© www.soinside.com 2019 - 2024. All rights reserved.