【发布时间】:2019-05-21 21:51:25
【问题描述】:
当我将 import org.springframework.data.annotation.Id; 添加到我的 Java 文件时,我收到此错误:
The import org.springframework.data cannot be resolved
我的直接想法是我缺少一个依赖项,但我不认为是这种情况。
这是我的 build.gradle 的依赖项。
dependencies {
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.synchronoss.cloud:nio-multipart-parser')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-data-mongodb-reactive')
compile('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
}
另外,我已经应用了这些插件:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
我是否遗漏了什么,或者我该如何解决这个问题?
其他信息。
我跑了./gradlew clean build --refresh-dependencies --debug。以下是日志的摘录:
22:25:30.664 [ERROR] [system.err] /Users/me/git/learning-spring-boot/learning-spring-boot-ch2/src/main/java/com/greglturnquist/learningspringboot/learningspringboot/ImageService.java:40: error: constructor Image in class Image cannot be applied to given types;
22:25:30.664 [ERROR] [system.err] new Image(path.hashCode(),
22:25:30.664 [ERROR] [system.err] ^
22:25:30.664 [ERROR] [system.err] required: String
22:25:30.665 [ERROR] [system.err] found: int,String
22:25:30.665 [ERROR] [system.err] reason: actual and formal argument lists differ in length
22:25:30.698 [ERROR] [system.err] /Users/me/git/learning-spring-boot/learning-spring-boot-ch2/src/main/java/com/greglturnquist/learningspringboot/learningspringboot/ApiController.java:26: error: constructor Image in class Image cannot be applied to given types;
22:25:30.700 [ERROR] [system.err] new Image("1", "learning-spring-boot-cover.jpg"),
22:25:30.700 [ERROR] [system.err] ^
22:25:30.700 [ERROR] [system.err] required: String
22:25:30.700 [ERROR] [system.err] found: String,String
22:25:30.701 [ERROR] [system.err] reason: actual and formal argument lists differ in length
22:25:30.701 [ERROR] [system.err] /Users/me/git/learning-spring-boot/learning-spring-boot-ch2/src/main/java/com/greglturnquist/learningspringboot/learningspringboot/ApiController.java:27: error: constructor Image in class Image cannot be applied to given types;
22:25:30.701 [ERROR] [system.err] new Image("2", "learning-spring-boot-2nd-edition-cover.jpg"),
22:25:30.702 [ERROR] [system.err] ^
22:25:30.702 [ERROR] [system.err] required: String
22:25:30.702 [ERROR] [system.err] found: String,String
22:25:30.702 [ERROR] [system.err] reason: actual and formal argument lists differ in length
22:25:30.705 [ERROR] [system.err] /Users/me/git/learning-spring-boot/learning-spring-boot-ch2/src/main/java/com/greglturnquist/learningspringboot/learningspringboot/ApiController.java:28: error: constructor Image in class Image cannot be applied to given types;
22:25:30.706 [ERROR] [system.err] new Image("3", "bazinga.png")
22:25:30.706 [ERROR] [system.err] ^
22:25:30.706 [ERROR] [system.err] required: String
22:25:30.706 [ERROR] [system.err] found: String,String
22:25:30.707 [ERROR] [system.err] reason: actual and formal argument lists differ in length
22:25:30.713 [ERROR] [system.err] 4 errors
22:25:30.716 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute compile for :compileJava'
22:25:30.726 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute compile for :compileJava' completed
22:25:30.733 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] Fingerprinting property destinationDir (Output) for task ':compileJava'
22:25:30.737 [LIFECYCLE] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache]
22:25:30.737 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache fileHashes.bin (/Users/me/git/learning-spring-boot/learning-spring-boot-ch2/.gradle/4.10.2/fileHashes/fileHashes.bin)
22:25:30.702 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger]
22:25:30.702 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :compileJava FAILED
22:25:30.738 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
22:25:30.739 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':compileJava'
22:25:30.740 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Task :compileJava'
22:25:30.740 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :compileJava' completed
22:25:30.741 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :compileJava (Thread[Task worker for ':',5,main]) completed. Took 59.344 secs.
22:25:30.741 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on :
22:25:30.742 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.13 completed (1 worker(s) in use)
22:25:30.743 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on root.1.13
22:25:30.743 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 7,5,main]] finished, busy: 0.0 secs, idle: 59.358 secs
22:25:30.744 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':',5,main]] finished, busy: 59.353 secs, idle: 0.006 secs
22:25:30.743 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':' Thread 3,5,main]] finished, busy: 0.0 secs, idle: 59.358 secs
22:25:30.743 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':' Thread 2,5,main]] finished, busy: 0.0 secs, idle: 59.36 secs
22:25:30.748 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskExecutionGraph] Timing: Executing the DAG took 59.365 secs
22:25:30.748 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Run tasks'
22:25:30.748 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Run tasks' completed
22:25:30.749 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':compileJava'.
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Compilation failed; see the compiler error output for details.
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
22:25:30.750 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
22:25:30.751 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. Run with --scan to get full insights.
22:25:30.751 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
22:25:30.751 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org
22:25:30.751 [WARN] [org.gradle.internal.featurelifecycle.LoggingDeprecatedFeatureHandler]
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
22:25:30.751 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger]
22:25:30.751 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 1m 47s
我检查了./gradlew dependenciesorg.springframework.boot:spring-boot-starter-data-mongodb-reactive -> 2.2.0.BUILD-SNAPSHOT 包含org.springframework.data:spring-data-mongodb:2.1.4.BUILD-SNAPSHOT,其中包含org.springframework:spring-context:5.1.3.RELEASE -> 5.1.4.BUILD-SNAPSHOT。难道org.springframework:spring-context:5.1.3.RELEASE -> 5.1.4.BUILD-SNAPSHOT不是兼容版本?
【问题讨论】:
-
你是否使用了应用插件:'io.spring.dependency-management'? (或弹簧靴)
-
是的。我添加了应用于问题的插件。
-
尝试清理您的项目并重新安装依赖项。
-
尝试应用插件:'spring-boot'
标签: java spring-boot gradle importerror