diff --git a/pom.xml b/pom.xml
index 4bf3d66f9ec40e49e113e1c9987513946f27e19f..1c38cf59da3ae11c7ae5ba5cc8ca24edf39a6863 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,9 @@
UTF-8
UTF-8
1.4.1.Final
+ 1.9.6
+ 2.9.2
+ 1.5.24
@@ -102,17 +105,6 @@
redis.clients
jedis
-
-
- io.springfox
- springfox-swagger2
- 2.6.1
-
-
- io.springfox
- springfox-swagger-ui
- 2.6.1
-
org.springframework.boot
spring-boot-starter-mail
@@ -140,13 +132,11 @@
dynamic-datasource-spring-boot-starter
3.5.1
-
com.theokanning.openai-gpt3-java
service
0.11.0
-
com.theokanning.openai-gpt3-java
client
@@ -175,7 +165,6 @@
4.12
test
-
org.mapstruct
mapstruct
@@ -192,6 +181,36 @@
hanlp
portable-1.8.3
+
+ io.springfox
+ springfox-swagger2
+ ${swagger.version}
+
+
+ io.swagger
+ swagger-annotations
+
+
+ io.swagger
+ swagger-models
+
+
+
+
+ io.swagger
+ swagger-annotations
+ ${swagger-models.version}
+
+
+ io.swagger
+ swagger-models
+ ${swagger-models.version}
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${swagger.version}
+
diff --git a/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java b/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
index 15bcf6e6f224beb2ae9a64e8b980cb918a52235a..1aa0afa380c5fa9ab9c0a11f23f0049a9a15ed38 100644
--- a/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
+++ b/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
@@ -2,18 +2,18 @@ package com.kwan.springbootkwan;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
-
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+@EnableSwagger2
@EnableScheduling
-@SpringBootApplication
@EnableBatchProcessing
+@SpringBootApplication
public class SpringBootKwanApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootKwanApplication.class, args);
System.out.println("------------------SpringBootKwan应用启动成功--------------------");
}
-
}
diff --git a/src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java b/src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
index 42bc12caf43f79490a552242974dc271054bee20..a608e343d5a57127896c814213048afb063c76fc 100644
--- a/src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
+++ b/src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
@@ -1,7 +1,6 @@
package com.kwan.springbootkwan.config;
import org.springframework.boot.validation.MessageInterpolatorFactory;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.format.FormatterRegistry;
@@ -14,7 +13,17 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
-import org.springframework.web.servlet.config.annotation.*;
+import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -29,6 +38,21 @@ import java.util.List;
@Configuration
public class MyWebMvcConfig extends WebMvcConfigurationSupport implements WebMvcConfigurer {
+ /**
+ * 配置静态资源
+ *
+ * @param registry
+ */
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/static/**")
+ .addResourceLocations("classpath:/static/");
+ registry.addResourceHandler("swagger-ui.html")
+ .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
+ registry.addResourceHandler("/webjars/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
+
@Override
public void extendMessageConverters(List> converters) {
// 解决controller返回字符串中文乱码问题
@@ -57,7 +81,6 @@ public class MyWebMvcConfig extends WebMvcConfigurationSupport implements WebMvc
messageSource.setDefaultEncoding("utf-8");// 读取配置文件的编码格式
messageSource.setCacheMillis(-1);// 缓存时间,-1表示不过期
messageSource.setBasename("ValidationMessages");// 配置文件前缀名,设置为Messages,那你的配置文件必须以Messages.properties/Message_en.properties...
-
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory();
factoryBean.setMessageInterpolator(interpolatorFactory.getObject());
@@ -70,17 +93,6 @@ public class MyWebMvcConfig extends WebMvcConfigurationSupport implements WebMvc
return WebMvcConfigurer.super.getMessageCodesResolver();
}
- /**
- * 配置静态资源
- *
- * @param registry
- */
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/static/**")
- .addResourceLocations("classpath:/static/");
- }
-
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
WebMvcConfigurer.super.configurePathMatch(configurer);
@@ -156,4 +168,4 @@ public class MyWebMvcConfig extends WebMvcConfigurationSupport implements WebMvc
public void configureMessageConverters(List> converters) {
WebMvcConfigurer.super.configureMessageConverters(converters);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java b/src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
index aab803d51339f64e189f90dc119b067c85c62268..0f0e6ca1ad53409a1f4c1bcc55766cc14c073c67 100644
--- a/src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
+++ b/src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
@@ -2,6 +2,8 @@ package com.kwan.springbootkwan.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -23,9 +25,15 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
public class Swagger2Config {
@Bean
- public Docket createRestApi() {
+ public Docket createRestApi(Environment environment) {
+ // 配置swagger的docket的bean实例
+ Profiles profiles = Profiles.of("dev", "test", "local");
+ // 通过environment.acceptsProfiles()判断是否指定的环境中,是,则为true
+ boolean flag = environment.acceptsProfiles(profiles);
return new Docket(DocumentationType.SWAGGER_2)
.groupName("SpringBoot学习")
+ .pathMapping("/")
+ .enable(flag)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.kwan.springbootkwan.controller"))//需要生成接口文档的包名
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 904dd7d0526091f680f82629873de0d944d23fda..4426832ed909a5be2a6ccef4e4b32644e042c1e0 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -26,9 +26,6 @@ spring:
#seata:
# tx-service-group: default_tx_group
-swagger:
- enable: true
-
#seata:
# application-id: spring-boot-name
# tx-service-group: my-tx-group