簡體   English   中英

如何更改spring mockmvc的http端口

[英]How to change http port of spring mockmvc

我正在使用vertx開發一個帶有三個端點的簡單api。

那api有一些我無法修改的預定義測試,我需要傳遞,使用:

@Autowired
private GenericWebApplicationContext webApplicationContext;
private MockMvc mockMvc;

在完成api之后,我發現當我使用Verticle時,我不需要提供spring boot starter依賴的嵌入式tomcat,所以我刪除了它。

哪個是我的問題?

我不能排除嵌入式tomcat,因為spring boot需要它,否則我將收到以下錯誤: The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured. The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured. 作為vertx verticle和tomcat監聽同一個端口(8080)。

這里的問題是我可以將Verticle端口更改為8081,但是需要將測試執行到端口8080.如何解決這個問題,以便測試監聽我部署的Verticle(這也創建了一個http服務器) )?

基本上我想知道MockHttpServletResponse是否可能使用由verticle而不是嵌入式tomcat創建的vertx服務器。

問題可能出在你的pom.xml和@Configuration類中。 嘗試將此依賴項添加到您的pom.xml。 因此,當您將war文件部署到服務器時,它將運行正常的tomcat而不是embeded

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

在你的Application類中寫這個

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

public static void main(String[] args) {

    SpringApplication.run(Application.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
}

}

那么你面臨的問題是tomcat已經啟動所以它在端口8080上偵聽你試圖運行另一個tomcat來監聽同樣的問題。

如果要啟動新的,則必須關閉舊的tomcat實例

在您的application.properties文件中輸入server.port = 8080或8082,您可以使用netstat -aon使用命令提示符查看哪個進程正在使用該端口並終止它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM