我想创建一个具有返回值的协程方法.
例如)
fun funA() = async(CommonPool) {
return 1
}
fun funB() = async(CommonPool) {
return 2
}
fun sum() {
launch {
val total = funA().await() + funB().await()
}
}
Run Code Online (Sandbox Code Playgroud)
如果我想要求总和方法,我该怎么办?
喜欢,
fun sum(): Int {
launch {
val total = funA().await() + funB().await()
}
return total
}
Run Code Online (Sandbox Code Playgroud) 在Spring Boot 1.5.x中,我正在创建RestTemplate如下的自定义:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
poolingConnectionManager.setMaxTotal(restTemplateProps.getMaxConnectionsPerPool());
poolingConnectionManager.setDefaultMaxPerRoute(restTemplateProps.getMaxDefaultConnectionPerRoute());
CloseableHttpClient client = HttpClientBuilder.create().setConnectionManager(poolingConnectionManager).build();
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
new HttpComponentsClientHttpRequestFactory(client);
clientHttpRequestFactory.setConnectTimeout(restTemplateProps.getConnectionTimeout());
clientHttpRequestFactory.setReadTimeout(restTemplateProps.getSocketTimeout());
return restTemplateBuilder.requestFactory(clientHttpRequestFactory).build();
}
Run Code Online (Sandbox Code Playgroud)
但是,在迁移到Spring Boot 2.1.x之后,上面的代码无法编译。看起来好像requestFactory不HttpComponentsClientHttpRequestFactory作为输入参数。
谁能建议我如何在Spring Boot 2.1.x中实现以上代码?
我需要得到的,从一个日期4-5-4日历周.是否有像Java格鲁吉亚日历这样的实用程序用于4-5-4零售日历?如果没有,我该如何创建一个?需要什么逻辑?在闰年的情况下,第53周是什么时候?
例如,如果我传递一个日期(DD-MM-YYY)04-03-2018作为输入,我应该得到March Week 1输出.或者,如果我提供01-04-2018输入,我应该得到March Week 5输出.
请通过提供构建此实用程序的方法来帮助我.
我正在使用Jacoco进行单元测试代码覆盖。Jacoco生成的报告显示,我的Kotlin代码中几乎没有遗漏任何分支。我注意到协程代码,之后的代码根据Jacoco未被正确覆盖。我不确定这是因为协程或其他原因。使用IntelliJ代码覆盖率运行单元测试时,我的Kotlin类显示100%的覆盖率。
我不知道为什么Jacoco的报道范围减少了。我已经使用Spock(Groovy)编写了单元测试。
请参考以下图片:
I need to add a Custom Header in all my RestTemplate Client requests. So I implemented ClientHttpRequestInterceptor. And I add the interceptor in my RestTemplateBuilder config like shown below. The problem is that when the RestTemplate makes the HTTP call it throws following exception:
java.lang.ClassCastException: org.springframework.http.client.InterceptingClientHttpRequestFactory cannot be cast to org.springframework.http.client.HttpComponentsClientHttpRequestFactory
Run Code Online (Sandbox Code Playgroud)
RestTemplate Bean Creation :
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
poolingConnectionManager.setMaxTotal(restTemplateProps.getMaxConnectionsPerPool());
poolingConnectionManager.setDefaultMaxPerRoute(restTemplateProps.getMaxDefaultConnectionPerRoute());
CloseableHttpClient client = HttpClientBuilder.create().setConnectionManager(poolingConnectionManager).build();
ClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(client);
restTemplateBuilder = …Run Code Online (Sandbox Code Playgroud) 我想使用链接将多个值发送到不同的页面href。但我检索到的只是前两个值,其余的显示未定义索引的错误。
我的代码是:
<?php
echo "<a href='index.php?choice=search&cat=".$cat."&subcat=".$subcat."&srch=".$srch."&page=".$next."'> Next </a>";
?>
Run Code Online (Sandbox Code Playgroud)
我只得到“选择”和“猫”的值。请告诉我上面的代码有什么问题。
java ×3
kotlin ×2
spring-boot ×2
calendar ×1
jacoco ×1
php ×1
resttemplate ×1
spock ×1
spring-rest ×1