嗨,我正在使用弹簧靴.我想动态替换属性文件中变量的内容.
这是我的档案: message.properties
message=Welcome ${bean.name} to my website
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何方法可以改变我的变量的值.谢谢
简单的问题:是否可以使用 ObjectMapper 覆盖@JsonSerialize注释(using属性)?
我已经spring-security-oauth2集成了,我想自定义OAuth2Exception序列化为 JSON 格式的方式。问题是这个类使用
@JsonSerialize(using = OAuth2ExceptionJackson2Serializer.class)
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下方式注册自定义序列化器:
SimpleModule module = new SimpleModule()
module.addSerializer(OAuth2Exception, new JsonSerializer<OAuth2Exception>() {
@Override
void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeString('{"test":"test"}')
}
})
ObjectMapper objectMapper = new ObjectMapper()
objectMapper.registerModule(module)
Run Code Online (Sandbox Code Playgroud)
但它不起作用 -@JsonSerialize使用设置的序列化器而不是自定义序列化器。
还有其他方法可以替换序列化器集吗@JsonSerialize?
PS:示例代码是这样写的groovy
我收集List<Foo>的Foo要素:
class Foo {
private TypeEnum type;
private int amount;
//getters, setters ...
}
Run Code Online (Sandbox Code Playgroud)
Foo类型可以TypeEnum.A和TypeEnum.B.
我想只Foo从列表中获取那些元素type == TypeEnum.B然后amount大于零(amount > 0)的元素.
我怎么能用Java 8 Streams filter()方法做到这一点?
如果我使用:
List<Foo> l = list.stream()
.filter(i -> i.getType().equals(TypeEnum.B) && i.getAmount() > 0)
.collect(Collectors.<Foo>toList());
Run Code Online (Sandbox Code Playgroud)
我得到了Foo元素,TypeEnum.B但没有TypeEnum.A.
如何使用spock检查深层对象是否相等.
假设我们有一个超级简单的测试,可以与相同的人物对象进行比较
def "A persons test"() {
setup:
def person1 = new Person("Foo", new Address("Bar"))
def person2 = new Person("Foo", new Address("Bar"))
expect:
person1 == person2
}
Run Code Online (Sandbox Code Playgroud)
测试失败
Condition not satisfied:
person1 == person2
| | |
| | Person@6bedbc4d
| false
Person@57af006c
Run Code Online (Sandbox Code Playgroud)
这看起来像是一种断言平等的非常自然的方式.
开始使用spock的主要原因之一是避免编写大量的hamcrest样板匹配器代码.
我有一个简单的Maven模块(不是Spring Boot应用程序),我放置了我的application.properties文件.
我有6-7个Spring Boot应用程序,我不想application.properties在每个应用程序目录中都有一个文件.我更喜欢它,如果它在一个地方(外部Maven模块).
我将maven模块添加为每个Spring Boot应用程序poms中的依赖项.
但是,当我运行这些应用程序时,它无法自动检测application.properties文件,因为它来自物理上不存在于每个应用程序目录中的依赖jar.
有没有办法让这成为可能?我想避免在6-7个不同的位置拥有属性文件,因为这很难管理和处理.
先感谢您!
我无法为泛型类编译Spock存根.构造函数的签名如下:
SomeClass(SerSup<Cap> capSup, String foo, String bar);
Run Code Online (Sandbox Code Playgroud)
我需要存根第一个参数.以下是我失败的尝试.
第一次尝试:
def someClass = new SomeClass(Stub(SerSup<Cap>), "foo", "bar")
Error: Groovyc: unexpected token: >
Status bar: ',' or ')' expected
Run Code Online (Sandbox Code Playgroud)
另一个尝试:
def someClass = new someClass(Stub(Cup) as SerSup<Cup>, "foo" ,"bar")
groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy10.get() is applicable for argument types: () values: []
Possible solutions: grep(), getAt(java.lang.String), grep(java.lang.Object), wait(), any(), wait(long)
at loom.SomeClass.SomeMethod(SomeClassTest.groovy:14)
Run Code Online (Sandbox Code Playgroud)
存根SomeClass构造函数的第一个参数的正确方法是什么?
我正在尝试将 groovy shell 脚本的输出保存在一个变量中。
test = sh(returnStdout: true, script: "#!/bin/bash -l && export VAULT_ADDR=http://ourVault.de:8100 && export VAULT_SKIP_VERIFY=true && vault auth ${VAULT_TOKEN} && vault read -field=value test/${RELEASE2}/ID").trim()
Run Code Online (Sandbox Code Playgroud)
但是没有输出,我想知道为什么它不捕获输出?
如果我这样做:
def test = ""
sh"""#!/bin/bash -l
export VAULT_ADDR=http://ourVault.de:8100
export VAULT_SKIP_VERIFY=true
vault auth ${VAULT_TOKEN}
${test}=\"\$(vault read -field=value emea/test/hockey/ios/${RELEASE2}/appID)\"
"""
Run Code Online (Sandbox Code Playgroud)
我在控制台中看到了输出。但是,它也不会被捕获。还有其他方法可以捕获多行 sh 脚本的输出吗?
我的Jenkinsfile中有:
def foo = ["1", "2", "3"]
def parallelStagesFromMap = foo.collectEntries {
["Build ${it}" : generateStage(it)]
}
def generateStage(bar) {
return {
stage("Build ${bar}") {
echo "Building for ${bar}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我可以并行使用它们,parallel parallelStagesFromMap但是现在我要特别调用一个,例如:
generateStage("a") 只是被跳过了...我错过了什么吗?
我想从 jenkins 作业向我在 Linux 服务器中编写的 shell 脚本之一发送一些参数。以下是我的詹金斯管道工作:
def MY_VAR
def BUILD_NUMBER
pipeline {
agent any
stages {
stage('Stage One') {
steps {
script {
BUILD_NUMBER={currentBuild.number}
MY_VAR ='abc'
}
}
}
stage('Stage Two') {
steps {
sh '''
cd /scripts/
./my_scripts.sh $BUILD_NUMBER $MY_VAR'''
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这里我可以发送 的值BUILD_NUMBER,但不能发送 的值MY_VAR。在我看来,自从MY_VAR被设置为管道以来,这就是它发生的原因。有人可以帮忙解决吗
我在 Jenkins 管道中创建了一个这样的类。
class Device
{
def ip = null
def context
def getIP(devName)
{
return "aaa.bbb.ccc.ddd"
}
Device(context, devName, devType)
{
print("[DEBUG] ctor device")
ip = getIP(devName)
this.context = context
print(ip)
}
}
ap = new Device(this, "DEV", "TYPE")
print ap.ip
Run Code Online (Sandbox Code Playgroud)
当我在“Groovy Web 控制台”( https://groovyconsole.appspot.com/ ) 中尝试它时效果很好,但是当我在 Jenkins 中运行此脚本时,会出现以下错误。
[Pipeline] Start of Pipeline
expected to call Device.<init> but wound up catching Device.getIP; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: CpsCallableInvocation{methodName=getIP, call=com.cloudbees.groovy.cps.impl.CpsFunction@20fd33e6, receiver=Device@57905ade, arguments=[DEV]}
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)
剧本有什么问题吗?
groovy ×5
java ×3
jenkins ×2
spock ×2
spring ×2
spring-boot ×2
equality ×1
generics ×1
jackson ×1
java-8 ×1
java-stream ×1
json ×1
shell ×1
unit-testing ×1