繁体   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