我正在使用Java Blade 框架。
我正在嘗試讓每臺服務器都偵聽自己的埠。但是,當運行兩個(或更多)服務器時,只有第一個可以作業。
當我嘗試在瀏覽器(服務器 2)中打開http://localhost:8082/world時,它會在第一臺服務器中查找必要的路由(我使用日志記錄發現了這一點)。我得到 404 錯誤。如果我交換服務器的開頭,則將在第一個中搜索所有路徑。
這是我的代碼:
public class App {
public static void main(String[] args) {
Blade.create()
.get("/hello", ctx -> ctx.text("hello!"))
.listen(8081)
.start()
.await();
Blade.create()
.get("/world", ctx -> ctx.text("world!"))
.listen(8082)
.start()
.await();
// http://localhost:8081/hello -> 202 ok
// http://localhost:8082/world -> 404 not found ->
// -> searches path "/world" in the first server
}
}
如何啟動兩臺服務器?
uj5u.com熱心網友回復:
感謝 Ilya Lapitan 對評論中的問題給出了完整的回答。
我還要補充一點,我能夠使用Javalin 庫在應用程式中運行 2 個服務器。代碼風格與 Blade 非常相似。
public class Application {
public static void main(String[] args) {
Javalin.create()
.get("/hello", ctx -> ctx.result("hello!"))
.start(8080);
Javalin.create()
.get("/world", ctx -> ctx.result("world!"))
.start(8081);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/511376.html
標籤:爪哇网络服务器
上一篇:即使隱藏,導航欄也會有點突出
