1.导入spring doc swagger api自动搜集库 \n2.新增application-prod.yml生产环境配置文件中, application spring.profile.active控制切换环境.\n3.配置文件中通过springdoc来控制是否开启springdoc
This commit is contained in:
parent
afb5ef3d2c
commit
ddc5a9a7d0
24
pom.xml
24
pom.xml
@ -30,6 +30,9 @@
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<springfox-swagger2>2.9.2</springfox-swagger2>
|
||||
<springfox-swagger-ui>2.9.2</springfox-swagger-ui>
|
||||
<springdoc-openapi-starter-webmvc-ui>2.5.0</springdoc-openapi-starter-webmvc-ui>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -64,6 +67,27 @@
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Swagger 2 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.springfox</groupId>-->
|
||||
<!-- <artifactId>springfox-swagger2</artifactId>-->
|
||||
<!-- <version>${springfox-swagger2}</version> <!– 或最新版本 –>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.springfox</groupId>-->
|
||||
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
|
||||
<!-- <version>${springfox-swagger-ui}</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- 添加 springdoc -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>${springdoc-openapi-starter-webmvc-ui}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package com.example.testspring.demos.modules.common.config;
|
||||
|
||||
|
||||
//import io.swagger.v3.oas.annotations.info.Info;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@Configuration
|
||||
@Profile("dev")
|
||||
public class OpenApiConfig {
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info()
|
||||
.title("API文档")
|
||||
.version("1.0.0")
|
||||
.description("Spring Boot项目接口说明")
|
||||
.contact(new io.swagger.v3.oas.models.info.Contact()
|
||||
.name("作者")
|
||||
.url("https://example.com")
|
||||
.email("contact@example.com")));
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,9 @@ import com.example.testspring.demos.modules.user.entity.SysMenu;
|
||||
import com.example.testspring.demos.modules.user.entity.SysUser;
|
||||
import com.example.testspring.demos.modules.user.service.IRobotService;
|
||||
import com.example.testspring.demos.modules.user.service.ISysUserService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -16,6 +19,7 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
@Tag(name = "测试接口")
|
||||
public class testController {
|
||||
|
||||
@Autowired
|
||||
@ -30,11 +34,13 @@ public class testController {
|
||||
// }
|
||||
|
||||
@GetMapping("/testRobot")
|
||||
@Operation(summary = "测试获取机器人列表")
|
||||
public List<Robot> test(){
|
||||
return robotService.selectRobotList(new Robot());
|
||||
}
|
||||
|
||||
@GetMapping("/testR")
|
||||
@Operation(summary = "测试获取机器人列表--以指定格式返回")
|
||||
public R testR(){
|
||||
return R.ok().put("data",robotService.selectRobotList(new Robot()));
|
||||
}
|
||||
|
||||
@ -44,4 +44,10 @@ spring:
|
||||
merge-sql: true
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
multi-statement-allow: true
|
||||
|
||||
springdoc:
|
||||
api-docs:
|
||||
enabled: true
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
53
src/main/resources/application-prod.yml
Normal file
53
src/main/resources/application-prod.yml
Normal file
@ -0,0 +1,53 @@
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource # 如使用Druid则取消注释
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: 'jdbc:mysql://localhost:3306/ruoyi-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8'
|
||||
url: 'jdbc:mysql://localhost:3306/kangda?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8'
|
||||
username: root
|
||||
password: root
|
||||
# Druid 连接池专属配置区 (注意缩进对齐)
|
||||
druid:
|
||||
# 从库数据源
|
||||
slave:
|
||||
enabled: false
|
||||
url: ''
|
||||
username: ''
|
||||
password: ''
|
||||
# 连接池配置
|
||||
initial-size: 5
|
||||
min-idle: 10
|
||||
max-active: 20
|
||||
max-wait: 60000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
max-evictable-idle-time-millis: 900000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# Web监控配置
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
allow: # 白名单
|
||||
url-pattern: /druid/*
|
||||
login-username: ruoyi
|
||||
login-password: 123456
|
||||
# 过滤器配置
|
||||
filter:
|
||||
stat:
|
||||
enabled: true
|
||||
log-slow-sql: true
|
||||
slow-sql-millis: 1000
|
||||
merge-sql: true
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
|
||||
springdoc:
|
||||
api-docs:
|
||||
enabled: false
|
||||
swagger-ui:
|
||||
enabled: false
|
||||
@ -2,6 +2,12 @@ spring:
|
||||
application:
|
||||
name: testspring
|
||||
|
||||
|
||||
# mvc:
|
||||
# # ????, ?????swagger???????
|
||||
# pathmatch:
|
||||
# matching-strategy: ANT_PATH_MATCHER # ??ant????
|
||||
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user