在Dropwizard服务运行方法上获取主机名



我正在尝试使用dropwizard+swagger来拥有一个rest api。。。它是文档。

我发现的问题是,swagger在初始化将为文档服务的资源时需要设置"basePath"属性:

@Override
public void run(MyServiceConfiguration configuration, Environment environment) throws Exception {
    ...
    ...
    // Set the swagger config options
    SwaggerConfig config = ConfigFactory.config();
    config.setApiVersion("1.0.0");
    config.setBasePath("http://localhost:9090/api");

我可以从配置参数中获取端口和根路径。但是,当我使用服务运行方法时,有什么方法可以真正获得协议+主机名吗?

尝试设置这样的相对路径:

config.setBasePath(".." + environment.getApplicationContext().getContextPath());

最新更新