小编Szy*_*iak的帖子

获取java.lang.NoSuchMethodException:使用PropertyUtils.setSimpleProperty函数时,属性“ xx”在类“类xx”中没有setter方法

我正在使用PropertyUtils.setSimpleProperty来动态调用我的setter方法,但是由于某些原因,我一直在出错。需要您的协助以找出根本原因。这是我的代码:

class FileDt {
    String reportName=null;
    String reportLocation=null;

    public String getReportName() {
        return reportName;
    }
    public void setReportName(String reportName) {
        this.reportName = reportName;
    }
    public String getReportLocation() {
        return reportLocation;
    }
    public void setReportLocation(String reportLocation) {
        this.reportLocation = reportLocation;
    }
}

class Foo {
    public static void main (String... args) {
        FileDt dt = newFileDt();
        // #1
        PropertyUtilsBean.setSimpleProperty(dt, "reportName", "abc.html");
        // #2
        PropertyUtilsBean.setSimpleProperty(dt, "reportLocation", "c://");
    }
}
Run Code Online (Sandbox Code Playgroud)

这两种方法都抛出异常

  1. 由以下原因引起:java.lang.NoSuchMethodException:属性'reportName'在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)的类'FileDt'中没有setter方法

  2. 由以下原因引起:java.lang.NoSuchMethodException:属性'reportLocation'在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)的类'FileDt'中没有setter方法

java javabeans nosuchmethoderror

5
推荐指数
1
解决办法
702
查看次数

在步骤中找不到这样的 DSL 方法“管道”

对于 Jenkins 中的声明性管道脚本,我不断收到此错误。

No such DSL method 'pipeline' found among steps
Run Code Online (Sandbox Code Playgroud)

我的脚本是这样的

pipeline {
    agent any
    stages {
        stage('Example Build') {
            steps {
                echo 'Hello World'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我有 Jenkins 版本 2.19.4。希望我已经安装了所有必需的插件。为什么我会收到此异常?

groovy jenkins jenkins-pipeline

5
推荐指数
1
解决办法
7308
查看次数

将 Gradle 依赖项保存到目录

如何将模块的所有依赖 jars 保存到目录中?我有一个在 IntelliJ IDEA 中运行的应用程序,但我想在另一台计算机上运行它,因此我需要将所有 JAR 文件复制到那里。

java intellij-idea gradle

5
推荐指数
1
解决办法
2130
查看次数

如何打印Groovy列表并保留报价?

我们有一个清单:

List test = ["a", "b", "c"]
Run Code Online (Sandbox Code Playgroud)

我不想更改此列表的硬编码,因为它有很多项目。

当像这样打印时:

println "${test}"
Run Code Online (Sandbox Code Playgroud)

我们得到[a, b, c]但我想拥有["a", "b", "c"]

有什么建议么?

string groovy list concatenation

5
推荐指数
2
解决办法
5356
查看次数

为什么要在 @PactVerification 中断言?

我不明白断言在@PactVerification. 对我来说,这更像是一种复杂的说法1 == 1。例如:

import static org.assertj.core.api.Assertions.assertThat;
public class PactConsumerDrivenContractUnitTest {
    @Rule
    public PactProviderRuleMk2 mockProvider
      = new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
    @Pact(consumer = "test_consumer")
    public RequestResponsePact createPact(PactDslWithProvider builder) {            
        return builder
          .given("test GET ")
          .uponReceiving("GET REQUEST")
          .path("/")
          .method("GET")
          .willRespondWith()
          .body("{\"condition\": true, \"name\": \"tom\"}")
    }
    @Test
    @PactVerification()
    public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() {
        //when
        ResponseEntity<String> response
          = new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
        //then
        assertThat(response.getBody()).contains("condition", "true", "name", "tom");        
    }
}
Run Code Online (Sandbox Code Playgroud)

所以首先在“createPact”中我们声明

body("{\"condition\": true, \"name\": \"tom\"}")
Run Code Online (Sandbox Code Playgroud)

然后在givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody注释中@PactVerification我们这样做

assertThat(response.getBody()).contains("condition", "true", …
Run Code Online (Sandbox Code Playgroud)

pact pact-jvm

5
推荐指数
1
解决办法
1688
查看次数

Can not infer functional interface type in groupBy Java 8

I am not sure this has been answered earlier or not. Can anyone please tell me what is the problem with third groupBy which I've written ? Why it can not infer ?

class TestGroupBy
{
    enum LifeCycle {
        ANNUAL, PERENNIAL
    }

    private String name;
    private LifeCycle lifeCycle;

    TestGroupBy(String name, LifeCycle lifeCycle) {
        this.name = name;
        this.lifeCycle = lifeCycle;
    }

    LifeCycle getLifeCycle() {
        return this.lifeCycle;
    }

    static EnumMap mySupplier() {
        return new EnumMap(TestGroupBy.class);
    }

    public static void main(String[] args) { …
Run Code Online (Sandbox Code Playgroud)

java java-8 collectors

5
推荐指数
1
解决办法
2111
查看次数

如何告诉 Spock 以特定顺序运行哪个类

我使用 Spock 进行测试,我有多个类要测试。我想告诉 Spock 按特定顺序测试每个类。有没有办法做到这一点?我注意到 TestNG 有@AfterTest注释,所以 Spock 有类似的东西吗?

groovy spock

5
推荐指数
1
解决办法
2643
查看次数

带有 Integer 键的 Groovy 映射 - DefaultGroovyMethods 中的“getAt”无法应用于 (java.lang.Integer)

我刚刚开始练习 Groovy,我有一个与地图和 IDEA IDE 相关的问题。

Integer当我尝试用作地图的密钥时,为什么 IDEA 会显示以下通知?这个简单的 Groovy 脚本运行良好并打印正确的结果。

截屏

list = [4, 7, 3, 7, 7, 1, 4, 2, 4, 2, 7, 5]

map = [:]
list.each {
    t = map[(it)]
    map[(it)] = t != null ? t + 1 : 1
}

map.each {key, value -> if (value == 1) println key}
Run Code Online (Sandbox Code Playgroud)

groovy intellij-idea

5
推荐指数
1
解决办法
1510
查看次数

Jenkins Pipeline sleep(10)阻止功能完成

我在Jenkinsfile中发现了Groovy代码的奇怪问题:

@NonCPS
def test() {
  println "Start"
  sleep(10)
  println "Stop"
}
Run Code Online (Sandbox Code Playgroud)

事实是,睡眠10秒钟之后,代码就再也无法进入了println "Stop"
看来,睡眠会在10秒后返回并运行下一个管道步骤。

输出只是:

[Pipieline] echo
Start
[Pipeline] sleep
Sleeping for 10 sec
[Pipeline] }
 ... next pipeline steps
Run Code Online (Sandbox Code Playgroud)

有人遇到过同样的问题吗?

groovy jenkins jenkins-pipeline

5
推荐指数
1
解决办法
3934
查看次数

如何将 groovy 映射转换为 json

我在 Jenkins 管道中有以下代码:

stage ("distribution"){
            steps{
                script{
                    def rules = [
                            service_name: "core", 
                            site_name: "*", 
                            city_name: "*", 
                            country_codes: ["*"]
                ]
                    amd_distribution_distribute_bundle distribution_rules: rules
                    }
                }
            }
Run Code Online (Sandbox Code Playgroud)

如您所见,它是一个地图参数。如何使用 Groovy 代码将其转换为 JSON 文件?最后它应该是这样的:

{
  "distribution_rules": [
    {
      "service_name": "core*",
      "site_name": "*",
      "city_name": "*",
      "country_codes": ["*"]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下命令,但没有帮助:

import groovy.json.JsonBuilder
import groovy.json.JsonOutput

def call(Map parameters)
{
    def DISTRIBUTION_RULES = parameters.distribution_rules
    def json = new groovy.json.JsonBuilder()
    json rootKey: "${DISTRIBUTION_RULES}"
    writeFile file: 'rootKey', text: JsonOutput.toJson(json)
}
Run Code Online (Sandbox Code Playgroud)

groovy jenkins-groovy jenkins-pipeline

5
推荐指数
1
解决办法
1978
查看次数