如何解决错误“包org.springframework.web.bind.annotation不存在”

yfjy0ee7  于 2023-02-11  发布在  Spring
关注(0)|答案(3)|浏览(580)
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
mv1qrgav

mv1qrgav1#

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

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

8wtpewkr2#

当我尝试使用gradle构建带有spring Boot 的项目时,我遇到了类似的问题。默认情况下,springboot项目是使用build.gradle文件中的此引用创建的:

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}}

更改此参考:

org.springframework.boot:spring-boot-starter

为此:

org.springframework.boot:spring-boot-starter-web

对我很有效。

bf1o4zei

bf1o4zei3#

更改此参考:
实现'org.springframework.boot:Spring引导启动程序'
为此:
实现'org. springframework. boot:spring-boot-starter-web'它对我很有效。

相关问题