简体   繁体   English

Spring Batch:无法识别 ItemProcessor 接口

[英]Spring Batch: Cannot recognize ItemProcessor Interface

I am a beginner just started learning Spring Batch.我是初学者,刚开始学习 Spring Batch。 I followed this tutorial here to create a helloworld example.在这里按照本教程创建了一个 helloworld 示例。 While I was following the tutorial, I encountered a problem when I was trying to import org.springframework.batch.item.ItemProcessor into a java class.在学习教程的过程中,我在尝试将org.springframework.batch.item.ItemProcessor导入 java 类时遇到了问题。 Hence I searched online and found out that I need to add something inside the build.gradle.因此我在网上搜索,发现我需要在 build.gradle 中添加一些东西。 The problem was, even though I have added the org.springframework.batch:spring-batch-core dependency in build.gradle, I was still having error message for the import.问题是,即使我在 build.gradle 中添加了org.springframework.batch:spring-batch-core依赖项,我仍然有导入的错误消息。 I am using Eclipse Java EE IDE 4.5.0 (Mars) to do this tutorial and have installed the Spring Test Suite (by following the tutorial).我正在使用 Eclipse Java EE IDE 4.5.0 (Mars) 来完成本教程并安装了 Spring Test Suite(按照教程进行操作)。 I have also tried right clicking the project and choose the "refresh" option but the error message is still there.我也尝试过右键单击项目并选择“刷新”选项,但错误消息仍然存在。

Additional note: I have also tried to follow the answer stated here but I cannot find the "Refresh Dependencies" in the "Gradle" context menu.附加说明:我也尝试按照此处所述的答案进行操作但在“Gradle”上下文菜单中找不到“Refresh Dependencies”。 How do you even know that the build.gradle is working?你怎么知道 build.gradle 正在工作?

Below is my code (Java class) that imports the Spring Batch:下面是我导入 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
    }
}

Below is the build.gradle file:下面是 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'
}

I had the same problem with the same tutorial except that I use IntelliJ instead of Eclipse.除了我使用 IntelliJ 而不是 Eclipse 之外,我在同一个教程中遇到了同样的问题。 On IntelliJ there is a "Gradle" panel on the right side that you can open and click refresh.在 IntelliJ 的右侧有一个“Gradle”面板,您可以打开它并单击刷新。 This will refresh your gradle.这将刷新你的gradle。 It solved the problem in my case.它解决了我的问题。 (Rebuilding gradle.build didn't) (重建 gradle.build 没有)

指向gradle面板的红色箭头

指向刷新图标的红色箭头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM