Commit d6528ae4 authored by 以墨为白's avatar 以墨为白 🎧

swagger替换成knife4j。注意springboot版本和knife4j版本的对应关系

parent 937de8ea
...@@ -116,15 +116,21 @@ ...@@ -116,15 +116,21 @@
</dependency> </dependency>
<!--swagger2--> <!--swagger2-->
<!-- <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>-->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>com.github.xiaoymin</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.9.2</version> <version>2.0.7</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -14,8 +14,9 @@ import springfox.documentation.service.Contact; ...@@ -14,8 +14,9 @@ import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter; import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import org.springframework.beans.factory.annotation.Value;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -24,10 +25,15 @@ import java.util.List; ...@@ -24,10 +25,15 @@ import java.util.List;
* Created by wcy on 2023/5/14. * Created by wcy on 2023/5/14.
*/ */
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2WebMvc
@Profile("dev")//dev环境下开启swagger功能 @Profile("dev")//dev环境下开启swagger功能
public class SwaggerConfig { public class SwaggerConfig {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SwaggerConfig.class);
@Value("${server.port:8005}")
private String port;
@Bean @Bean
public Docket createRestApi() { public Docket createRestApi() {
...@@ -42,6 +48,8 @@ public class SwaggerConfig { ...@@ -42,6 +48,8 @@ public class SwaggerConfig {
pars.add(param3); pars.add(param3);
pars.add(param4); pars.add(param4);
pars.add(param5); pars.add(param5);
log.info("http://localhost:{}/doc.html", port);
ApiInfo apiInfo = new ApiInfoBuilder() ApiInfo apiInfo = new ApiInfoBuilder()
.title("模块服务接口文档") .title("模块服务接口文档")
.description("服务接口文档,遵循RESTful API设计规范") .description("服务接口文档,遵循RESTful API设计规范")
......
...@@ -43,7 +43,7 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -43,7 +43,7 @@ public class WebConfig implements WebMvcConfigurer {
registry.addResourceHandler("/favicon.ico", "/demo_upload.html", "/images/favicon-32x32.png", "/images/favicon-16x16.png", "/excel/newsList.xlsx") registry.addResourceHandler("/favicon.ico", "/demo_upload.html", "/images/favicon-32x32.png", "/images/favicon-16x16.png", "/excel/newsList.xlsx")
.addResourceLocations("classpath:/static/"); .addResourceLocations("classpath:/static/");
// 解决 swagger-ui.html 404报错 // 解决 swagger-ui.html 404报错
registry.addResourceHandler("swagger-ui.html").addResourceLocations( registry.addResourceHandler("doc.html").addResourceLocations(
"classpath:/META-INF/resources/"); "classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations( registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/"); "classpath:/META-INF/resources/webjars/");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment