首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Apache上测试Spring网络流量性能

无法在Apache上测试Spring网络流量性能
EN

Stack Overflow用户
提问于 2017-11-22 15:57:20
回答 1查看 459关注 0票数 3

在使用Apache测试spring反应性项目的性能时,我遇到了一个问题。

代码语言:javascript
复制
ab http://localhost:8080/hi

结果显示超时。

但对curl http://localhost:8080/hi来说没问题

我的项目使用Spring版本为2.0.0.M6。我会粘贴一些代码。

pom.xml是

代码语言:javascript
复制
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-reactor-netty</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>

MyRouter.java

代码语言:javascript
复制
@Component
public class MyRouter {
    private static final Logger logger = LoggerFactory.getLogger(MyRouter.class);
    @Bean
    RouterFunction<ServerResponse> router(PersonHandler personHandler) {
        return route(GET("/hi"), request -> ok().body(BodyInserters.fromObject("hello")));
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-22 16:22:39

这是由于ab在调用netty服务器时的错误。

要解决这个问题,只需在响应头中添加"Connection: closed“即可。但这不是最终的解决办法。

MyRouter.java

代码语言:javascript
复制
@Component
public class MyRouter {
    private static final Logger logger = LoggerFactory.getLogger(MyRouter.class);
    @Bean
    RouterFunction<ServerResponse> router(PersonHandler personHandler) {
        return route(GET("/hi"), request -> ok().header("Connection", "close").body(BodyInserters.fromObject("hello")));
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47438990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档