java - 我不包括 java.lang.String bean?

标签 java string spring gradle groovy

我有一个用 Groovy 编写的小型 Spring Boot 测试项目,使用 Gradle 构建。当尝试使用

运行时
spring run src/com/eval/EvalMain.groovy src/com/eval/InputObj.groov

我收到了

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.eval.InputObj required a bean of type 'java.lang.String' that could not be found.


Action:

Consider defining a bean of type 'java.lang.String' in your configuration.

我的印象是 gradle 为我提供了这些东西,而且它应该可以工作,因为 Groovy 是基于 Java 构建的。 (另外它是如何知道包路径java.lang?)下面是我的gradle.build,任何帮助将不胜感激!

buildscript {
    ext {
        springBootVersion = '1.4.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'testJar'
    version = '.0.0.2'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

springBoot {
    mainClass = "com.eval.EvalMain"
}

最佳答案

I was under the impression that gradle included these kinds of things for me, and that it should work since Groovy is built on Java.

构造函数 com.eval.InputObj 需要一个类型为“java.lang.String”的 bean 异常与 Gradle 作为您的 InputObj 无关code> bean 对象需要一个构造函数参数,该参数是一个 String 参数,您需要提供该参数(使用 spring config xml 或注释) 来创建 bean/对象。

关于java - 我不包括 java.lang.String bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40670099/

相关文章:

python - 在多个文件中搜索多个子字符串的索引

java - Spring IoC - 确保在 @PostConstruct/afterProperiesSet 之前创建所有 bean

java - 使用 Spring Boot Rest API 的非典型 JSON 配置

java - 使用 Jersey 和 MOXy 将 JSON 反序列化为列表集合

java - Android 无法添加 getByName

c - 你如何在 C 中声明字符串常量?

java - Spring QueryByExampleExecutor 空结果

java - 使用 JAVA REPL 解释 Dataflow JAVA SDK 命令

java - 为什么在 Java 中创建 'const' 关键字?

javascript - 无法使用子字符串从javascript获取所需的值