Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
58ca08bc
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
58ca08bc
编写于
8月 26, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:配置swagger
上级
6e27ca4c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
36 deletion
+72
-36
pom.xml
pom.xml
+33
-14
src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
...va/com/kwan/springbootkwan/SpringBootKwanApplication.java
+3
-3
src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
...n/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
+27
-15
src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
...n/java/com/kwan/springbootkwan/config/Swagger2Config.java
+9
-1
src/main/resources/application.yaml
src/main/resources/application.yaml
+0
-3
未找到文件。
pom.xml
浏览文件 @
58ca08bc
...
...
@@ -19,6 +19,9 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<mapstruct.version>
1.4.1.Final
</mapstruct.version>
<swagger-bootstrap-ui.version>
1.9.6
</swagger-bootstrap-ui.version>
<swagger.version>
2.9.2
</swagger.version>
<swagger-models.version>
1.5.24
</swagger-models.version>
</properties>
<dependencies>
<dependency>
...
...
@@ -102,17 +105,6 @@
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
</dependency>
<!--集成swagger-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.6.1
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.6.1
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-mail
</artifactId>
...
...
@@ -140,13 +132,11 @@
<artifactId>
dynamic-datasource-spring-boot-starter
</artifactId>
<version>
3.5.1
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.theokanning.openai-gpt3-java/service -->
<dependency>
<groupId>
com.theokanning.openai-gpt3-java
</groupId>
<artifactId>
service
</artifactId>
<version>
0.11.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.theokanning.openai-gpt3-java/client -->
<dependency>
<groupId>
com.theokanning.openai-gpt3-java
</groupId>
<artifactId>
client
</artifactId>
...
...
@@ -175,7 +165,6 @@
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct
</artifactId>
...
...
@@ -192,6 +181,36 @@
<artifactId>
hanlp
</artifactId>
<version>
portable-1.8.3
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
${swagger.version}
</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>
${swagger-models.version}
</version>
</dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<artifactId>
swagger-models
</artifactId>
<version>
${swagger-models.version}
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
${swagger.version}
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
浏览文件 @
58ca08bc
...
...
@@ -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应用启动成功--------------------"
);
}
}
src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
浏览文件 @
58ca08bc
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
<
HttpMessageConverter
<?>>
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
<
HttpMessageConverter
<?>>
converters
)
{
WebMvcConfigurer
.
super
.
configureMessageConverters
(
converters
);
}
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
浏览文件 @
58ca08bc
...
...
@@ -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"
))
//需要生成接口文档的包名
...
...
src/main/resources/application.yaml
浏览文件 @
58ca08bc
...
...
@@ -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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录