java 报错“package org.springframework.web.bind.annotation does not exist”如何解决

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27498605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 11:53:42  来源:igfitidea点击:

How to Solve the error "package org.springframework.web.bind.annotation does not exist"

javaspringspring-mvccompiler-errors

提问by Harika Kusuma

jagadeesh-Gs-MacBook:Contact jagadeeshgundlapalle$ gradle
:help

Welcome to Gradle 2.2.1.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

BUILD SUCCESSFUL

Total time: 16.4 secs
jagadeesh-Gs-MacBook:Contact jagadeeshgundlapalle$ gradle jar
:compileJava
/Users/jagadeeshgundlapalle/Documents/workspace3/Contact/src/main/java/gurukul/ContactListController.java:4: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.RequestMapping;
                                              ^
/Users/jagadeeshgundlapalle/Documents/workspace3/Contact/src/main/java/gurukul/ContactListController.java:5: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.RequestParam;
                                              ^
/Users/jagadeeshgundlapalle/Documents/workspace3/Contact/src/main/java/gurukul/ContactListController.java:6: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.RestController;
                                              ^
/Users/jagadeeshgundlapalle/Documents/workspace3/Contact/src/main/java/gurukul/ContactListController.java:9: cannot find symbol
symbol: class RestController
@RestController
 ^
/Users/jagadeeshgundlapalle/Documents/workspace3/Contact/src/main/java/gurukul/ContactListController.java:14: cannot find symbol
symbol  : class RequestMapping
location: class gurukul.ContactListController
    @RequestMapping("/getList")
     ^
5 errors
:compileJava FAILED

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.

BUILD FAILED

Total time: 11.53 secs

回答by Jens

add the spring-web.jar to your dependecies:

将 spring-web.jar 添加到您的依赖项中:

org.springframework:spring-web:<your spring version>.RELEASE