我正在写一些groovy脚本.直到现在我只需使用记事本并通过脚本运行groovy script.groovy
.但我正在寻找一些编辑文件的帮助.所以我尝试使用groovy插件进行eclipse,看起来很棒......对于常规项目.但我只是想编辑和运行groovy脚本.没有项目目录等.在eclipse中处理脚本的最佳方法是什么.我不想将文件打包到罐子或类似的东西.我只有一个包含一些脚本的文件夹...没有src/bin目录或包名称的子文件夹.那可能吗?
谢谢,Ingo
我只是在使用Groovy中的元类编程.但突然间,我遇到了一个我无法工作的小问题......
这是一个简单的脚本:
// define simple closure
def printValueClosure = {
println "The value is: '$delegate'"
}
String.metaClass.printValueClosure = printValueClosure
// works fine
'variable A'.printValueClosure()
// define as method
def printValueMethod(String s){
println "The value is: '$s'"
}
// how to do this!?
String.metaClass.printValueMethod = this.&printValueMethod(delegate)
'variable B'.printValueMethod()
Run Code Online (Sandbox Code Playgroud)
是否可以使用该方法,但将第一个参数设置为调用对象?使用委托似乎不起作用...不引用调用者的方法的分配是没有问题的.curry在这里工作吗?
谢谢,Ingo
我真的很喜欢在 Java 14 中添加记录,至少作为预览功能,因为它有助于减少我将 lombok 用于简单、不可变的“数据持有者”的需要。但是我在实现可空组件时遇到了问题。我试图避免null
在我的代码库中返回以表明某个值可能不存在。因此,我目前经常在 lombok 中使用类似以下模式的内容。
@Value
public class MyClass {
String id;
@Nullable String value;
Optional<String> getValue() { // overwrite the generated getter
return Optional.ofNullable(this.value);
}
}
Run Code Online (Sandbox Code Playgroud)
当我现在对记录尝试相同的模式时,不允许声明incorrect component accessor return type
.
record MyRecord (String id, @Nullable String value){
Optional<String> value(){
return Optional.ofNullable(this.value);
}
}
Run Code Online (Sandbox Code Playgroud)
因为我认为Optional
现在首选使用s 作为返回类型,所以我真的很想知道为什么会有这个限制。我对用法的理解有误吗?如何在不添加另一个带有不隐藏默认签名的签名的访问器的情况下实现相同的目标?如果Optional
不是在这种情况下,在所有被使用?
我有一个Java EE应用程序,其中模型从各种来源非常频繁地更新.此外,我有一个富客户端应用程序,它通过远程EJB触发一些操作,但也应该至少每秒显示一次模型更改.
将更改从Java EE应用程序发送到Java客户端应用程序的最简单/最佳选择是什么?直到现在我有以下选择:
我使用 SpringBoot 2.1 和 来spring-boot-maven-plugin
自动git-commit-id-plugin
使用构建信息填充执行器信息端点。效果很好。我将值分组在 json 属性build
和git
.
现在我还想将这些信息包含在 json 格式的日志消息中(使用 logback logstash)。因此我尝试使用springProperty
扩展,但似乎这些元素不能用作环境条目。
<springProperty scope="context" name="info_version" source="info.build.version"/>
<springProperty scope="context" name="build_version" source="build.version"/>
Run Code Online (Sandbox Code Playgroud)
我这两种情况都没有得到解决。build-info.properties
我还尝试通过手动添加作为属性源
@PropertySource("classpath:META-INF/build-info.properties")
Run Code Online (Sandbox Code Playgroud)
...但这似乎也不起作用。
因此,如何在日志消息中包含信息条目中的构建版本、git-commit 或其他内容等属性?