gradle 页面不存在页面不存在

vhmi4jdf  于 2023-01-02  发布在  其他
关注(0)|答案(1)|浏览(211)

每次我运行它的时候,我都会得到FAILURE: Build failed with an exception.,因为org.springframework.web.bind.annotation does not exist,但是它在项目中,当我输入代码的时候,我没有得到任何错误,只有当我运行它的时候。
就好像我的项目没有检测到org.springframework.web.bind.annotation库。
这是我的控制器:

package com.example.springprojectjpapostgres.Controllers;

import com.example.springprojectjpapostgres.Models.UserModel;
import com.example.springprojectjpapostgres.Services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping()
    public ArrayList<UserModel> getUsers(){
        return userService.getUsers();
    }

    @PostMapping()
    public UserModel postUser(@RequestBody UserModel user){
        return this.userService.postUser(user);
    }
}

当我运行它时,我得到以下错误:

:55:30 AM: Executing ':classes'...

> Task :compileJava FAILED
1 actionable task: 1 executed
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:6: error: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.RestController;
                                              ^
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:7: error: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.GetMapping;
                                              ^
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:8: error: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.RequestMapping;
                                              ^
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:9: error: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.PostMapping;
                                              ^
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:10: error: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.RequestBody;
                                              ^
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:15: error: cannot find symbol
@RestController
 ^
  symbol: class RestController
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:16: error: cannot find symbol
@RequestMapping("/user")
 ^
  symbol: class RequestMapping
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:21: error: cannot find symbol
    @GetMapping()
     ^
  symbol:   class GetMapping
  location: class UserController
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:27: error: cannot find symbol
    public UserModel postUser(@RequestBody UserModel user){
                               ^
  symbol:   class RequestBody
  location: class UserController
/home/themachine/IdeaProjects/SpringProject_JPA_Postgres/src/main/java/com/example/springprojectjpapostgres/Controllers/UserController.java:26: error: cannot find symbol
    @PostMapping()
     ^
  symbol:   class PostMapping
  location: class UserController
10 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 419ms
9:55:30 AM: Execution finished ':classes'.

我的项目中有JPA,这是我的build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.1'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'org.postgresql:postgresql'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

我会感激任何帮助和新年快乐!!🎆🥳🎉

相关问题