spring boot 添加swagger支持
添加maven依赖
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>3.0.0</version> </dependency>
添加java 类
@Configuration public class SpringFoxConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } }
访问地址
ip:port/${context-path}/swagger-ui/
如果报这个
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
添加如下spring 配置
spring: mvc: pathmatch: matching-strategy: ant_path_matcher
参考
https://stackoverflow.com/questions/40241843/failed-to-start-bean-documentationpluginsbootstrapper-in-spring-data-rest
https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
posted on 2023-03-10 15:08 cococooder 阅读(27) 评论(0) 编辑 收藏 举报