list.stream().forEach(e -> { dbCall.delete(e.Id());});
列表中的每一项都会从数据库中删除。
假设列表中有3项,如何进行单元测试:
我制作了一个简单的应用程序以连接到MySQL数据库,但出现此错误:
org.springframework.jdbc.core.JdbcTemplate
在我的配置中(com.kubamadry.dao.MySqlStudentDao)
:
*****************************
APPLICATION FAILED TO START
*****************************
Description:
Field jdbcTemplate in com.kubamadry.dao.MySqlStudentDao required a bean of type 'org.springframework.jdbc.core.JdbcTemplate' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.jdbc.core.JdbcTemplate' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:49838', transport: 'socket'
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
项目结构:
班级
主要
package com.kubamadry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
public static void main(String args[]) {
SpringApplication.run(Main.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
学生
package …
Run Code Online (Sandbox Code Playgroud) 最近升级到 Java 11 并开始执行回归检查。当前在尝试调用 时收到非法反射访问错误com.itextpdf.text.pdf.PdfReader.close
。目前在 Itext 5.5.13 版上,但也在 itext 7.0.0 上尝试过并且遇到了同样的问题。
有没有人对如何解决 Java-11 和 Itext 之间的兼容性问题有任何建议?
警告:发生非法反射访问操作警告:com.itextpdf.io.source.ByteBufferRandomAccessSource$1 非法反射访问(文件:...repository/com/itextpdf/io/7.0.0/io-7.0.0.jar ) 方法 java.nio.DirectByteBuffer.cleaner() 警告:请考虑将此报告给 com.itextpdf.io.source.ByteBufferRandomAccessSource$1 的维护者 警告:使用 --illegal-access=warn 启用进一步非法反射访问的警告操作警告:在未来的版本中将拒绝所有非法访问操作
我正在尝试选择最好的方法来并行进行大量的http请求。以下是我到目前为止拥有的两种方法:
使用Apache HttpAsyncClient和CompletableFutures:
try (CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setMaxConnPerRoute(2000).setMaxConnTotal(2000)
.setUserAgent("Mozilla/4.0")
.build()) {
httpclient.start();
HttpGet request = new HttpGet("http://bing.com/");
long start = System.currentTimeMillis();
CompletableFuture.allOf(
Stream.generate(()->request).limit(1000).map(req -> {
CompletableFuture<Void> future = new CompletableFuture<>();
httpclient.execute(req, new FutureCallback<HttpResponse>() {
@Override
public void completed(final HttpResponse response) {
System.out.println("Completed with: " + response.getStatusLine().getStatusCode())
future.complete(null);
}
...
});
System.out.println("Started request");
return future;
}).toArray(CompletableFuture[]::new)).get();
Run Code Online (Sandbox Code Playgroud)常规的每请求线程数方法:
long start1 = System.currentTimeMillis();
URL url = new URL("http://bing.com/");
ExecutorService executor = Executors.newCachedThreadPool();
Stream.generate(()->url).limit(1000).forEach(requestUrl ->{
executor.submit(()->{
try {
URLConnection conn = requestUrl.openConnection();
System.out.println("Completed …
Run Code Online (Sandbox Code Playgroud)我有一个对象列表.该对象如下所示:
public class Slots {
String slotType;
Visits visit;
}
public class Visits {
private long visitCode;
private String agendaCode;
private String scheduledTime;
private String resourceType;
private String resourceDescription;
private String visitTypeCode;
...
}
Run Code Online (Sandbox Code Playgroud)
我需要找到具有相同元素的元素agendaCode
,visitTypeCode
并且scheduledTime
在我的生活中我无法完成它.
我试过这个:
Set<String> agendas = slotsResponse.getContent().stream()
.map(Slots::getVisit)
.map(Visits::getAgendaCode)
.collect(Collectors.toUnmodifiableSet());
Set<String> visitTypeCode = slotsResponse.getContent().stream()
.map(Slots::getVisit)
.map(Visits::getVisitTypeCode)
.collect(Collectors.toUnmodifiableSet());
Set<String> scheduledTime = slotsResponse.getContent().stream()
.map(Slots::getVisit)
.map(Visits::getScheduledTime)
.collect(Collectors.toUnmodifiableSet());
List<Slots> collect = slotsResponse.getContent().stream()
.filter(c -> agendas.contains(c.getVisit().getAgendaCode()))
.filter(c -> visitTypeCode.contains(c.getVisit().getVisitTypeCode()))
.filter(c -> scheduledTime.contains(c.getVisit().getScheduledTime()))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但它没有做我想的那样.理想情况下,我会有一个列表列表,其中每个子列表是共享相同的Slots对象的列表agendaCode
, …
我有两个int数组,a = {10,20,30}
和{1,2,3}
.
我想获得这两个阵列的笛卡尔积.
当我使用List
的Integer
S中的逻辑正常工作:
List<Integer> intList = Arrays.asList(10,20,30);
List<Integer> intList1 = Arrays.asList(1,2,3);
intList.stream().flatMap(i -> intList1.stream().map(j -> new int[]{i,j})).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但是,当我使用时int[]
,我收到编译错误.
错误:(16,79)java:不兼容类型:lambda表达式中的错误返回类型没有变量类型的实例U存在以便java.util.stream.Stream符合java.util.stream.IntStream
int[] intArray = {10,20,30};
int[] intArray1 = {1,2,3};
Arrays.stream(intArray).flatMap(i -> Arrays.stream(intArray1).mapToObj(j -> new int[]{j,i})).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
请帮我理解这里有什么问题.
PS
Arrays.stream(intArray).mapToObj(i -> new int[]{i,i+1}).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
产生出局, {(10,11),(20,21),(30,31)}
.
我正在使用Selenium webdriver在Java
.
该工具将通过Jenkins调用在无头服务器上运行。我的问题是处理多个文件上传。Selenium无法打开浏览器,所以当我点击网站上的上传按钮时,也没有出现选择文件弹出窗口。
我想知道是否还有其他解决方案可以让我在自动化测试期间处理上传的多文件。
PS我可以使用sendkeys
功能处理单个文件上传。但我不能这样做来处理多个文件上传。
PPS 我不能使用AutoIT或Robot
class 来处理弹出对话框(因为无头服务器没有弹出对话框)
我正在使用码头(9.4.12)在macOS(Java 11)上提供Web应用程序。
尽管码头已经启动,但该服务仍然不可用。我和往常一样使用了相同的War文件,但是唯一的区别是,我已经将Java从版本10更新到了版本11。这个问题是否有可能的修复?
错误
Failed startup of context o.e.j.w.WebAppContext@2af004b{jaltantra,/jaltantra,file:///private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/,UNAVAILABLE}{/jaltantra.war}
MultiException[java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/optimizer/Pipe.class,
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/optimizer/Pipe$FlowType.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/EPATool$NodeVariableType.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/quality/QualitySim.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/quality/QualitySim$1.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/EPATool.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Link$LinkType.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Control.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Curve.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Source.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Field$RangeType.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/NUConvert.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Tank.class
java.lang.RuntimeException: Error scanning file /private/var/folders/s8/sgl02rb122xcl3bfc22wtfch0000gn/T/jetty-0.0.0.0-8080-jaltantra.war-_jaltantra-any-4267422187513106243.dir/webapp/WEB-INF/classes/org/addition/epanet/network/structures/Link.class
java.lang.RuntimeException: …
Run Code Online (Sandbox Code Playgroud) 我在制作中遇到了一个有趣的问题.
我有以下ScheduledThreadPool
分配代码:
ScheduledExecutorService executorService =
Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() - 1);
Run Code Online (Sandbox Code Playgroud)
线程池定期处理队列中的一些任务.一切都运行正常,直到服务部署在单个核心环境中.显然,上面的行转换为:
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(0);
Run Code Online (Sandbox Code Playgroud)
从那时起,JVM进程的CPU利用率一直在100%左右.在我改变Runtime.getRuntime().availableProcessors() - 1
为不变1
的那一刻,问题已经消失.
找出根本原因花了一些时间,但我仍然不知道背后的原因.ScheduledExecutorService
JavaDoc声明:
/**
* Creates a thread pool that can schedule commands to run after a
* given delay, or to execute periodically.
* @param corePoolSize the number of threads to keep in the pool,
* even if they are idle
* @return a newly created scheduled thread pool
* @throws IllegalArgumentException if {@code corePoolSize …
Run Code Online (Sandbox Code Playgroud) java ×10
java-stream ×3
java-11 ×2
performance ×2
asynchronous ×1
http ×1
integer ×1
itext ×1
itext7 ×1
java-module ×1
jetty ×1
jetty-9 ×1
jls ×1
selenium ×1
spring ×1
spring-bean ×1
spring-boot ×1
spring-jdbc ×1
testing ×1
threadpool ×1
unit-testing ×1
vavr ×1