当前位置: 首页 > wzjs >正文

800元建网站西安行业网站

800元建网站,西安行业网站,软件定制开发公司官网,孝感市建设网站以下是 Springfox Swagger 的完整配置及同类框架对比的详细说明&#xff1a; 一、Springfox Swagger 配置详解 1. 添加依赖 在 pom.xml 中添加以下依赖&#xff1a; <!-- Springfox Swagger 2 --> <dependency><groupId>io.springfox</groupId>…

以下是 Springfox + Swagger 的完整配置及同类框架对比的详细说明:
在这里插入图片描述
在这里插入图片描述


一、Springfox + Swagger 配置详解

1. 添加依赖

pom.xml 中添加以下依赖:

<!-- Springfox Swagger 2 -->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>3.0.0</version> <!-- 注意版本兼容性 -->
</dependency>
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>3.0.0</version>
</dependency>

2. 配置类(SwaggerConfig.java)
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
public class SwaggerConfig {@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 指定Controller包路径.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))// 指定路径(可选,PathSelectors.any() 表示所有路径).paths(PathSelectors.ant("/api/**")).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("API文档").description("系统接口文档").version("1.0.0").contact(new Contact("开发者", "https://example.com", "dev@example.com")).license("Apache 2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html").build();}
}

3. 自定义访问地址

通过修改 application.propertiesapplication.yml 自定义 Swagger UI 的访问路径:

# application.properties
springfox.documentation.swagger.v2.path=/custom-api-docs
springfox.documentation.swagger-ui.path=/custom-swagger-ui

访问地址变为:
http://localhost:8080/custom-swagger-ui


4. Controller 示例
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/api")
@Api(tags = "示例接口") // 接口分组标签
public class ExampleController {@GetMapping("/hello")@ApiOperation("Hello接口")public String sayHello() {return "Hello, Swagger!";}
}

二、同类框架对比

1. Springdoc OpenAPI
  • 特点
    • 支持 OpenAPI 3.0 标准。
    • 自动扫描,无需复杂配置。
    • 支持 Swagger UI 和 ReDoc。
  • 配置示例
    <!-- pom.xml -->
    <dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-ui</artifactId><version>1.6.12</version>
    </dependency>
    
  # application.propertiesspringdoc.api-docs.path=/api-docsspringdoc.swagger-ui.path=/swagger-ui
  • 访问地址http://localhost:8080/swagger-ui

2. Swagger UI (官方版)
  • 特点
    • 官方维护的 UI 组件。
    • 需手动配置 OpenAPI 定义文件。
    • 灵活适配多种后端技术。
  • 配置示例
    <!-- pom.xml -->
    <dependency><groupId>io.swagger.core.v3</groupId><artifactId>swagger-ui</artifactId><version>2.2.10</version>
    </dependency>
    
  @SpringBootApplicationpublic class Application {public static void main(String[] args) {SpringApplication app = new SpringApplication(Application.class);// 配置 Swagger UI 路径app.setDefaultProperties(Collections.singletonMap("spring.resources.static-locations", "classpath:/META-INF/resources/"));app.run(args);}}

3. RAML
  • 特点
    • 基于 RAML(RESTful API Modeling Language)描述接口。
    • 支持自动生成文档和客户端代码。
    • 适合需要详细接口规范的团队。
  • 工具:使用 RAML ResolverRAML Console 生成文档。

4. Apigee
  • 特点
    • 企业级 API 管理平台。
    • 提供完整的 API 生命周期管理(发布、监控、安全等)。
    • 支持多语言文档生成。
  • 适用场景:大型分布式系统、微服务架构。

三、功能对比表格

框架支持协议配置复杂度适用场景核心功能访问方式
SpringfoxSwagger 2.0中等Spring Boot 项目、简单配置自动扫描、注解配置、支持分组http://localhost:8080/swagger-ui.html
Springdoc OpenAPIOpenAPI 3.0现代 Spring Boot 项目、自动扫描支持 OpenAPI 3、ReDoc、Swagger UIhttp://localhost:8080/swagger-ui
Swagger UIOpenAPI 2/3需手动配置 OpenAPI 定义文件灵活适配多种后端技术自定义路径
RAMLRAML需详细接口规范的团队自动生成文档和客户端代码需第三方工具支持
Apigee多种协议企业级 API 管理、复杂系统生命周期管理、监控、安全策略云端或私有部署

四、选择建议

  • 简单快速集成:选择 Springdoc OpenAPI(支持 OpenAPI 3,配置简单)。
  • Spring Boot 项目:优先 SpringfoxSpringdoc
  • 手动控制文档:使用 Swagger UIRAML
  • 企业级需求:选择 Apigee

通过以上配置和对比,您可以根据项目需求选择最合适的框架。


文章转载自:

http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://00000000.fkLcs.cn
http://www.dtcms.com/wzjs/620456.html

相关文章:

  • 做动图为所欲为的网站软件开发流程简介
  • 东莞网站建设的公司淘宝客登记新网站
  • 海南省建设银行官方网站招聘org后缀做网站行
  • 大淘客网站上的推广怎么做陕西网站建设公司找哪家
  • 网站拓扑图怎么做锡林郭勒盟网站建设
  • 做废旧回收哪个网站好关于做好学院网站建设的要求
  • yellow网站推广联盟网页不能下载的wordpress
  • 在家做网站设计什么网站容易做百度权重
  • 深圳网站开发哪家专业教学ppt模板免费下载完整版
  • 做网站要做相应的app吗外包网站开发合同
  • 平度推广网站建设临安做企业网站的公司
  • 滕州个人兼职做网站管理咨询网站建设
  • 天河建设网站公司网上注册公司的章程怎么下载出来
  • 有做学历在网站能查的到的网站建设平台官网要点有哪些
  • 保定哪家做网站公司好wordpress删除版权信息
  • 正规的app网站开发成都旅游学院简介
  • 如何撤销网站备案青岛seo排名公司
  • seo网站推广怎样深圳网站设计公司行业
  • 哪个网站建网页比较好备案查询工信部
  • 五寨网站建设安徽省建设工程信息网网
  • 怎么做视频解析网站吗河南省村镇建设处网站
  • 网页界面设计一般使用的分辨率东莞百度seo找哪里
  • discuz网站搬家教程网站建设的特征
  • 贵阳讯玛网站建设wordpress 图片墙
  • win7 网站系统怎么做友情链接购买
  • 刷单类网站开发wordpress zhong
  • 天津市津南区教育网站建设招标揭阳企业网页制作公司
  • 想自己做网站苏州专业做优化公司
  • 网站建设 腾云网络推广的方法
  • 网站横幅怎做西青网站文化建设