簡體   English   中英

Spring Batch:無法識別 ItemProcessor 接口

[英]Spring Batch: Cannot recognize ItemProcessor Interface

我是初學者,剛開始學習 Spring Batch。 在這里按照本教程創建了一個 helloworld 示例。 在學習教程的過程中,我在嘗試將org.springframework.batch.item.ItemProcessor導入 java 類時遇到了問題。 因此我在網上搜索,發現我需要在 build.gradle 中添加一些東西。 問題是,即使我在 build.gradle 中添加了org.springframework.batch:spring-batch-core依賴項,我仍然有導入的錯誤消息。 我正在使用 Eclipse Java EE IDE 4.5.0 (Mars) 來完成本教程並安裝了 Spring Test Suite(按照教程進行操作)。 我也嘗試過右鍵單擊項目並選擇“刷新”選項,但錯誤消息仍然存在。

附加說明:我也嘗試按照此處所述的答案進行操作但在“Gradle”上下文菜單中找不到“Refresh Dependencies”。 你怎么知道 build.gradle 正在工作?

下面是我導入 Spring Batch 的代碼(Java 類):

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//error message: "the import org.springframework.batch cannot be resolved"
import org.springframework.batch.item.ItemProcessor; 


//error message: "ItemProcessor cannot be resolved to a type"
public class PersonItemProcessor implements ItemProcessor<Person, Person> {

    @Override
    public Person process(final Person person) throws Exception {
        //some codes
    }
}

下面是 build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-consuming-rest'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.batch:spring-batch-core") //added by me
    compile("org.springframework.boot:spring-boot-starter")
    compile("org.springframework:spring-web")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

除了我使用 IntelliJ 而不是 Eclipse 之外,我在同一個教程中遇到了同樣的問題。 在 IntelliJ 的右側有一個“Gradle”面板,您可以打開它並單擊刷新。 這將刷新你的gradle。 它解決了我的問題。 (重建 gradle.build 沒有)

指向gradle面板的紅色箭頭

指向刷新圖標的紅色箭頭

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM