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
答案 0 :(得分:7)
将spring-web.jar添加到您的依赖项中:
org.springframework:spring-web:<your spring version>.RELEASE
答案 1 :(得分:3)
当我尝试使用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
对我有用。