Swagger-ui在idea中的使用

1.添加依赖

        <!--添加swagger2相关概念-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!--添加swagger-ui相关功能-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

2.配置文件:SwggerConfig

@Configuration//告诉Spring容器,这个类是一个配置类
@EnableSwagger2//启用Swagger2功能
public class SwaggerConfig {

    @Bean
    public Docket createResApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com"))//com包下的所有API都交给Swagger2管理
                .paths(PathSelectors.any()).build();
    }


    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("演示项目API")//标签
                .description("演示项目")//描述
                .version("1.0")//版本
                .build();
    }
}

3.访问地址

http://localhost:8080/swagger-ui.html

4.问题

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

#配置Swagger-ui
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

 Swagger常用注解

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用的内容,解决swagger2.9.2报错 For input string: "" 的问题时,可以尝试将swagger的annotations以及models替换为1.5.21版本。在pom.xml文件添加以下依赖: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </exclusion> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.22</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.22</version> </dependency> ``` 这样,你就能解决swagger2.9.2报错 For input string: "" 的问题了。如果你还遇到swagger不能传递参数的问题,可以参考引用提供的博客链接,了解解决方案。 在使用swagger传递参数时,你可以使用@ApiParam注解,如引用所示。在方法的参数上添加@ApiParam注解,指定参数的名称、值和是否必需。这样,你就能够在swagger正确传递参数了。但如果你仍然遇到Cannot resolve io.springfox:springfox-swagger-ui:unknown的问题,可能是你的项目没有正确引入swagger-ui的依赖。你可以检查一下你的pom.xml文件,确保有以下依赖的配置: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> ``` 这样,你就能够解决Cannot resolve io.springfox:springfox-swagger-ui:unknown的问题了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [解决idea添加依赖遇见Cannot resolve XXX的问题](https://blog.csdn.net/qq_56392291/article/details/131025683)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [swagger使用问题收集](https://blog.csdn.net/DATANGguanjunhou/article/details/102733213)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值