You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让FastAPI的Uvicorn端口与Eureka配置端口一致?

问题:让Uvicorn运行端口与Eureka配置端口一致

我希望Uvicorn的运行端口与Eureka配置的端口保持一致,已查找大量资料,尝试过相关方案但无效。以下是我的代码:

import py_eureka_client.eureka_client as eureka_client
import uvicorn
from fastapi import FastAPI
from contextlib import asynccontextmanager
from com.controladores import controladorRouter


@asynccontextmanager
async def lifespan(app: FastAPI):
    await eureka_client.init_async(
        eureka_server="http://eureka-primary:8011/eureka/,http://eureka-secondary:8012/eureka/,http://eureka-tertiary:8013/eureka/",
        app_name="msprueba",
        instance_port=8000,
        instance_host="localhost"
    )
    yield

app = FastAPI(lifespan=lifespan)
app.include_router(controladorRouter)

if __name__ == "__main__":
    config = uvicorn.Config("com.main:app", host="localhost", port=0)
    server = uvicorn.Server(config)
    server.run()

我之前使用SpringBoot时这项任务要简单得多,FastAPI本身是很棒的工具,但这个操作却遇到了困难,求帮助!

内容的提问来源于stack exchange,提问作者Alan Gaytan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 16:03:10