我收到的ArrayIndexOutOfBoundsException时候我用Java 8特性的服务启动(创建bean).
Java 8已经建立并一直在运行.代码编译正确.在服务启动时,服务无法侦听端口,因为bean未创建.当我更改代码(删除java 8构造)时,服务启动,一切正常.
这是我正在使用的代码(服务启动的工作代码):
for (Item itemObject : response) {
if (itemObject.hasId()) {
idList.add(String.valueOf(itemObject.Id());
}
}
Run Code Online (Sandbox Code Playgroud)
使用Java 8构造的相同代码:
response.parallelStream()
.filter(itemObject -> itemObject.hasId())
.map(itemObject -> itemObject.getId())
.forEach(id -> idList.add(id));
Run Code Online (Sandbox Code Playgroud)
包含这段代码的类的bean是使用组件扫描创建的.
当使用第二个代码块代替第一个代码块时,以下是异常消息:
Exiting with throwable: java.lang.IllegalArgumentException: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/workspace/.../GetContainerIdForFcSkuAdapter.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 51880
java.lang.IllegalArgumentException: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/workspace....Some.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 51880
Run Code Online (Sandbox Code Playgroud)
对我来说没有意义的是,为什么在创建bean时,函数内部的代码(不是bean类的构造函数)被覆盖.我问这个,因为当我使用普通for循环而不是并行流时,异常不存在.ArrayOutOfBoundsException当调用函数并且实际使用此代码时,不应该出现.
我该如何解决?
我已经浏览了https://docs.python.org/3/library/unittest.mock-examples.html页面,我看到他们已经列出了如何模拟生成器的示例
我有一个代码,我调用生成器给我一组值,我保存为字典.我想在单元测试中模拟对这个生成器的调用.
我写了以下代码,但它不起作用.
我哪里错了?
In [7]: items = [(1,'a'),(2,'a'),(3,'a')]
In [18]: def f():
print "here"
for i in [1,2,3]:
yield i,'a'
In [8]: def call_f():
...: my_dict = dict(f())
...: print my_dict[1]
...:
In [9]: call_f()
"here"
a
In [10]: import mock
In [18]: def test_call_f():
with mock.patch('__main__.f') as mock_f:
mock_f.iter.return_value = items
call_f()
....:
In [19]: test_call_f()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-19-33ca65a4f3eb> in <module>()
----> 1 test_call_f()
<ipython-input-18-92ff5f1363c8> in test_call_f()
2 with mock.patch('__main__.f') as …Run Code Online (Sandbox Code Playgroud) 我想将一个分支中的所有更改推送到另一个分支(现有分支)而不进行合并.
例如,考虑两个分支branch1到branch2.branch1和branch2分别跟踪origin/branch1和origin/branch2.
Branch1具有提交A,B,C,D,E,F Branch2具有提交A,B,D,F
我想让Branch2与branch1完全一样.采摘和合并樱桃会产生冲突,我不想花时间解决,因为我所要做的就是盲目地将branch1复制到branch2.
我能够做到这一点
git checkout branch1 # Moves to branch1
git push origin :branch2 # Deletes remote branch origin/branch2
git branch -d branch2 # Deletes the local copy of this branch
git pull
git push origin HEAD:branch2 # Creates new branch in remote repository from the HEAD at local branch branch1
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法通过合并命令中的一些--force选项来执行此操作.我不想每次都删除分支只是为了创建一个具有相同名称的新分支.
谢谢
我正在向我的 API 成功发出以下 curl 请求:
curl -v -X GET -H "Content-Type: application/json" -d {'"query":"some text","mode":"0"'} http://host.domain.abc.com:23423/api/start-trial-api/
Run Code Online (Sandbox Code Playgroud)
我想知道如何从 JAVA 代码内部发出此请求。我尝试通过 Google 和堆栈溢出搜索解决方案。我所发现的只是如何通过查询字符串发送数据或如何通过 POST 请求发送 JSON 数据。
谢谢
我正在寻找这个问题的正确解决方案.之前已经多次询问过这个问题,我没有找到适合的单一答案.我需要在NLTK中使用语料库来检测单词是否是英语单词
我试过这样做:
wordnet.synsets(word)
Run Code Online (Sandbox Code Playgroud)
对于许多常见词汇而言,这无法言喻.使用英语单词列表并在文件中执行查找不是一种选择.使用附魔也不是一种选择.如果有另一个库可以执行相同的操作,请提供api的用法.如果没有,请提供nltk语料库,其中包含所有英语单词.
我有一个非常大的类JSON文件,但它没有使用正确的JSON语法:没有引用对象键.我想编写一个脚本来修复文件,以便我可以加载它json.loads.
我需要匹配后跟冒号的所有单词,并用引用的单词替换它们.我认为正则表达式是\w+\s*:我应该使用的re.sub,但我不确定如何做到这一点.
如何获取以下输入并获得给定的输出?
# In
{abc : "xyz", cde : {}, fgh : ["hfz"]}
# Out
{"abc" : "xyz", "cde" : {}, "fgh" : ["hfz"]}
# In
{
a: "b",
b: {
c: "d",
d: []
},
e: "f"
}
# Out
{
"a": "b",
"b": {
"c": "d",
"d": []
},
"e": "f"
}
Run Code Online (Sandbox Code Playgroud)