首页主机资讯CentOS Swagger依赖怎么装

CentOS Swagger依赖怎么装

时间2026-01-16 10:49:04发布访客分类主机资讯浏览1250
导读:在CentOS上安装Swagger依赖,通常需要以下几个步骤: 1. 安装Java Swagger工具通常需要Java环境。你可以使用以下命令安装OpenJDK: sudo yum install java-1.8.0-openjdk-de...

在CentOS上安装Swagger依赖,通常需要以下几个步骤:

1. 安装Java

Swagger工具通常需要Java环境。你可以使用以下命令安装OpenJDK:

sudo yum install java-1.8.0-openjdk-devel

2. 安装Maven

Swagger工具通常使用Maven进行构建和管理依赖。你可以使用以下命令安装Maven:

sudo yum install maven

3. 安装Swagger工具

你可以使用Maven来下载和安装Swagger工具。以下是一个示例命令,用于下载Swagger UI:

mvn clean install -DskipTests

4. 配置Swagger

下载完成后,你可以将Swagger UI的静态文件部署到你的Web服务器上。例如,如果你使用的是Apache HTTP服务器,可以将Swagger UI的文件复制到你的Web服务器的根目录下。

5. 配置Spring Boot(如果使用Spring Boot)

如果你使用的是Spring Boot,可以在你的pom.xml文件中添加Swagger依赖:

<
    dependency>
    
    <
    groupId>
    io.springfox<
    /groupId>
    
    <
    artifactId>
    springfox-swagger2<
    /artifactId>
    
    <
    version>
    2.9.2<
    /version>
    
<
    /dependency>
    
<
    dependency>
    
    <
    groupId>
    io.springfox<
    /groupId>
    
    <
    artifactId>
    springfox-swagger-ui<
    /artifactId>
    
    <
    version>
    2.9.2<
    /version>
    
<
    /dependency>
    

然后,在你的Spring Boot应用程序中配置Swagger:

import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
import org.springframework.context.annotation.Bean;
    
import springfox.documentation.builders.PathSelectors;
    
import springfox.documentation.builders.RequestHandlerSelectors;
    
import springfox.documentation.spi.DocumentationType;
    
import springfox.documentation.spring.web.plugins.Docket;
    
import springfox.documentation.swagger.web.UiConfiguration;
    
import springfox.documentation.swagger.web.UiConfigurationBuilder;


@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
    
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo"))
                .paths(PathSelectors.any())
                .build();

    }


    @Bean
    public UiConfiguration uiConfig() {
    
        return UiConfigurationBuilder.builder()
                .deepLinking(true)
                .displayOperationId(false)
                .defaultModelsExpandDepth(1)
                .defaultModelExpandDepth(1)
                .defaultModelRendering(ModelRendering.EXAMPLE)
                .displayRequestDuration(false)
                .docExpansion(DocExpansion.NONE)
                .filter(false)
                .maxDisplayedTags(null)
                .operationsSorter(OperationsSorter.ALPHA)
                .showExtensions(false)
                .tagsSorter(TagsSorter.ALPHA)
                .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
                .validatorUrl(null)
                .build();

    }

}
    

6. 启动应用程序

启动你的Spring Boot应用程序,然后访问http://localhost:8080/swagger-ui.html即可看到Swagger UI界面。

通过以上步骤,你应该能够在CentOS上成功安装和配置Swagger依赖。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: CentOS Swagger依赖怎么装
本文地址: https://pptw.com/jishu/781279.html
CentOS Swagger如何部署到生产环境 CentOS Swagger如何集成到项目中

游客 回复需填写必要信息