添加es的接口

customer
gyc 2024-04-24 14:31:05 +08:00
parent 05772a382e
commit 50e7a0d557
26 changed files with 758 additions and 6 deletions

View File

@ -25,3 +25,4 @@ spring:
# 共享配置 # 共享配置
shared-configs: shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bawei</groupId>
<artifactId>base-es</artifactId>
<version>3.6.0</version>
</parent>
<artifactId>base-es-remote</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1 @@
com.bawei.file.remote.factory.RemoteFileFallbackFactory

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bawei</groupId>
<artifactId>base-es</artifactId>
<version>3.6.0</version>
</parent>
<artifactId>base-es-server</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Minio -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>${minio.version}</version>
</dependency>
<!-- BaWei Common Swagger -->
<dependency>
<groupId>com.bawei</groupId>
<artifactId>bawei-common-swagger</artifactId>
</dependency>
<dependency>
<groupId>com.bawei</groupId>
<artifactId>bawei-common-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,24 @@
package com.bawei.es;
import com.bawei.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* es
*
* @program: mall_cloud
* @ClassName: BaWeiEsApplication
* @author: Gyc
* @create: 2024-04-22 20:39
**/
@EnableCustomSwagger2
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
public class BaWeiEsApplication {
public static void main(String[] args)
{
SpringApplication.run(BaWeiEsApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ es服务模块启动成功 ლ(´ڡ`ლ)゙ ");
}
}

View File

@ -0,0 +1,58 @@
package com.bawei.es.controller;
import com.bawei.common.core.domain.R;
import com.bawei.es.service.DocService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController("/doc")
@Api(value = "es文档操作",tags = "首页")
public class DocController {
@Autowired
private DocService docService;
@ApiOperation(value = "根据索引名称和文档ID查询该索引文档")
@PostMapping("/getDocByIndexName/{indexName}/{id}")
public R getDocByIndexName(@PathVariable String indexName, @PathVariable String id){
if (id!=null){
return R.ok(docService.getDocByIndexName(indexName,id));
}
throw new RuntimeException("文档ID不能为空");
}
@ApiOperation(value = "增加es文档")
@PostMapping("/createDoc/{indexName}")
public R createDoc(@PathVariable String indexName, @RequestBody Map<String,Object> document){
if (document!=null && !CollectionUtils.isEmpty(document)){
return R.ok(docService.createDoc(indexName,document));
}
throw new RuntimeException("添加失败,文档不可为空");
}
@ApiOperation(value = "修改es文档")
@PutMapping("/putDoc/{indexName}")
public R putDoc(@PathVariable String indexName,@RequestBody Map<String,Object> document){
if (document!=null && !CollectionUtils.isEmpty(document)){
return R.ok(docService.putDoc(indexName,document));
}
throw new RuntimeException("修改失败,文档不可为空");
}
@ApiOperation(value = "删除es文档")
@DeleteMapping("/deleteDoc/{indexName}/{id}")
public R deleteDoc(@PathVariable String indexName, @PathVariable String id){
if (id!=null){
return R.ok(docService.deleteDoc(indexName,id));
}
throw new RuntimeException("文档ID不能为空");
}
}

View File

@ -0,0 +1,47 @@
package com.bawei.es.controller;
import com.bawei.common.core.domain.R;
import com.bawei.es.service.IndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author gyc
*/
@RestController("/index")
@Api(value = "es索引操作",tags = "首页")
public class IndexController {
@Autowired
private IndexService indexService;
@ApiOperation(value = "根据索引名称查询该索引是否存在")
@GetMapping("/index/{indexName}")
public R index(@PathVariable String indexName){
return R.ok(indexService.exits(indexName));
}
@ApiOperation(value = "创建索引")
@PostMapping("/create/{indexName}")
public R create(@PathVariable String indexName, @RequestBody Map<String,Object> mappings){
return R.ok(indexService.create(indexName,mappings));
}
@ApiOperation(value = "更新索引")
@PutMapping("/update/{indexName}")
public R update(@PathVariable String indexName,@RequestBody Map<String,Object> mappings){
return R.ok(indexService.update(indexName,mappings));
}
@ApiOperation(value = "删除索引")
@DeleteMapping("/delete/{indexName}")
public R delete(@PathVariable String indexName){
return R.ok(indexService.delete(indexName));
}
}

View File

@ -0,0 +1,15 @@
package com.bawei.es.service;
import com.bawei.common.core.domain.R;
import java.util.Map;
public interface DocService {
R getDocByIndexName(String indexName, String id);
R createDoc(String indexName, Map<String, Object> document);
R putDoc(String indexName, Map<String, Object> document);
R deleteDoc(String indexName, String id);
}

View File

@ -0,0 +1,15 @@
package com.bawei.es.service;
import com.bawei.common.core.domain.R;
import java.util.Map;
public interface IndexService {
Boolean exits(String indexName);
R create(String indexName, Map<String, Object> mappings);
R update(String indexName, Map<String, Object> mappings);
R delete(String indexName);
}

View File

@ -0,0 +1,136 @@
package com.bawei.es.service.impl;
import com.bawei.common.core.domain.R;
import com.bawei.es.service.DocService;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class DocServiceImpl implements DocService {
@Autowired
private IndexServiceImpl indexServiceImpl;
@Autowired
private RestHighLevelClient restHighLevelClient;
/**
*ID
* @param indexName
* @param id ID
* @return
*/
@Override
public R getDocByIndexName(String indexName, String id) {
//判断索引是否存在
if(!indexServiceImpl.exits(indexName)){
throw new RuntimeException("该索引不存在");
}
//构造获取文档请求
GetRequest getRequest = new GetRequest(indexName, id);
try {
GetResponse getResponse = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
//判断文档是否存在
if (getResponse.isExists()){
//获取文档内容
Map<String, Object> source = getResponse.getSource();
return R.ok(source);
}else {
throw new RuntimeException("该文档不存在");
}
} catch (Exception e) {
throw new RuntimeException("获取文档异常,异常信息为: "+e.getMessage(),e);
}
}
/**
* es
* @param indexName
* @param document
* @return
*/
@Override
public R createDoc(String indexName, Map<String, Object> document) {
if(!indexServiceImpl.exits(indexName)){
throw new RuntimeException("该索引不存在");
}
//构建一个索引请求,并指定索引名称
IndexRequest indexRequest = new IndexRequest(indexName);
indexRequest.source(document, XContentType.JSON);
try {
IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
if (indexResponse.getResult()== DocWriteResponse.Result.CREATED || indexResponse.getResult() == DocWriteResponse.Result.UPDATED){
return R.ok("文档添加成功");
}else {
throw new RuntimeException("文档添加失败");
}
} catch (Exception e) {
throw new RuntimeException("索引请求处理异常,异常信息为: "+e.getMessage(),e);
}
}
/**
* es
* @param indexName
* @param document
* @return
*/
@Override
public R putDoc(String indexName, Map<String, Object> document) {
if(!indexServiceImpl.exits(indexName)){
throw new RuntimeException("该索引不存在");
}
R r = this.putDoc(indexName, document);
if (r.isSuccess()){
return R.ok("修改成功");
}
throw new RuntimeException("修改失败");
}
/**
* es
* @param indexName
* @param id ID
* @return
*/
@Override
public R deleteDoc(String indexName, String id) {
if(!indexServiceImpl.exits(indexName)){
throw new RuntimeException("该索引不存在");
}
//构造删除文档请求
DeleteRequest deleteRequest = new DeleteRequest(indexName, id);
try {
DeleteResponse deleteResponse = restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
if (deleteResponse.getResult() == DocWriteResponse.Result.DELETED){
return R.ok("删除成功");
}else {
throw new RuntimeException("删除失败");
}
} catch (Exception e) {
throw new RuntimeException("索引请求处理异常,异常信息为: "+e.getMessage(),e);
}
}
}

View File

@ -0,0 +1,127 @@
package com.bawei.es.service.impl;
import com.bawei.common.core.domain.R;
import com.bawei.es.service.IndexService;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class IndexServiceImpl implements IndexService {
@Autowired
private RestHighLevelClient restHighLevelClient;
/**
*
* @param indexName
* @return /
*/
@Override
public Boolean exits(String indexName) {
GetIndexRequest indexRequest = new GetIndexRequest(indexName);
try {
boolean exists = restHighLevelClient.indices().exists(indexRequest, RequestOptions.DEFAULT);
if (exists){
return true;
}else {
throw new RuntimeException("该索引不存在");
}
} catch (Exception e) {
throw new RuntimeException("查找索引异常,异常信息为: "+e.getMessage(),e);
}
}
/**
*
* @param indexName
* @param mappings
* @return /
*/
@Override
public R create(String indexName, Map<String, Object> mappings) {
Boolean exits = this.exits(indexName);
if (exits){
throw new RuntimeException("该索引已存在");
}
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
// 将映射参数转换为 JSON 字符串并设置到索引请求中
try {
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder();
xContentBuilder.map(mappings);
createIndexRequest.mapping(xContentBuilder);
} catch (Exception e) {
throw new RuntimeException("构建映射失败,失败原因: "+e.getMessage(),e);
}
try {
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
if (createIndexResponse.isAcknowledged()){
return R.ok("创建成功");
}else {
throw new RuntimeException("创建索引失败");
}
} catch (Exception e) {
throw new RuntimeException("创建索引异常,异常信息为:"+e.getMessage(),e);
}
}
/**
*
* @param indexName
* @param mappings
* @return
*/
@Override
public R update(String indexName, Map<String, Object> mappings) {
Boolean exits = this.exits(indexName);
if (!exits){
throw new RuntimeException("该索引不存在");
}
R delete = delete(indexName);
if (delete.isSuccess()){
create(indexName,mappings);
return R.ok("更新成功");
}else {
throw new RuntimeException("更新失败");
}
}
/**
*
* @param indexName
* @return /
*/
@Override
public R delete(String indexName) {
Boolean exits = this.exits(indexName);
if (!exits){
throw new RuntimeException("该索引不存在");
}
try {
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
AcknowledgedResponse delete = restHighLevelClient.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
if (delete.isAcknowledged()){
return R.ok("删除成功");
}else {
throw new RuntimeException("删除失败");
}
} catch (Exception e) {
throw new RuntimeException("删除索引异常,异常信息为: "+e.getMessage(),e);
}
}
}

View File

@ -0,0 +1,10 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}
_ __ _ _
(_) / _|(_)| |
_ __ _ _ ___ _ _ _ ______ | |_ _ | | ___
| '__|| | | | / _ \ | | | || ||______|| _|| || | / _ \
| | | |_| || (_) || |_| || | | | | || || __/
|_| \__,_| \___/ \__, ||_| |_| |_||_| \___|
__/ |
|___/

View File

@ -0,0 +1,27 @@
# Tomcat
server:
port: 9003
# Spring
spring:
application:
# 应用名称
name: bawei-es
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 124.220.46.186:8848
namespace: 12345678
config:
# 配置中心地址
server-addr: 124.220.46.186:8848
namespace: 12345678
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/bawei-file" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.bawei" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<root level="info">
<appender-ref ref="console" />
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
</root>
</configuration>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bawei</groupId>
<artifactId>bawei-base</artifactId>
<version>3.6.0</version>
</parent>
<artifactId>base-es</artifactId>
<packaging>pom</packaging>
<description>
base-es es服务
</description>
<modules>
<module>base-es-server</module>
<module>base-es-remote</module>
</modules>
</project>

View File

@ -25,3 +25,14 @@ spring:
# 共享配置 # 共享配置
shared-configs: shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
api-docs:
path: v3/api-docs # 指定生成文档的路径,网关会访问这个路径来拉取文档
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.keyl1me.edu.controller # 指定要扫描的包
knife4j:
enable: true # 开启knife4j接口文档美化
setting:
language: zh_cn # 指定语言

View File

@ -31,3 +31,14 @@ mybatis:
typeAliasesPackage: com.bawei.gen.domain typeAliasesPackage: com.bawei.gen.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件 # 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml mapperLocations: classpath:mapper/**/*.xml
api-docs:
path: v3/api-docs # 指定生成文档的路径,网关会访问这个路径来拉取文档
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.keyl1me.edu.controller # 指定要扫描的包
knife4j:
enable: true # 开启knife4j接口文档美化
setting:
language: zh_cn # 指定语言

View File

@ -25,3 +25,14 @@ spring:
# 共享配置 # 共享配置
shared-configs: shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
api-docs:
path: v3/api-docs # 指定生成文档的路径,网关会访问这个路径来拉取文档
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.keyl1me.edu.controller # 指定要扫描的包
knife4j:
enable: true # 开启knife4j接口文档美化
setting:
language: zh_cn # 指定语言

View File

@ -25,3 +25,14 @@ spring:
# 共享配置 # 共享配置
shared-configs: shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
api-docs:
path: v3/api-docs # 指定生成文档的路径,网关会访问这个路径来拉取文档
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.keyl1me.edu.controller # 指定要扫描的包
knife4j:
enable: true # 开启knife4j接口文档美化
setting:
language: zh_cn # 指定语言

View File

@ -13,6 +13,8 @@
<module>base-gen</module> <module>base-gen</module>
<module>base-job</module> <module>base-job</module>
<module>base-file</module> <module>base-file</module>
<module>base-es</module>
</modules> </modules>
<artifactId>bawei-base</artifactId> <artifactId>bawei-base</artifactId>

View File

@ -29,6 +29,11 @@
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>${swagger.fox.version}</version> <version>${swagger.fox.version}</version>
</dependency> </dependency>
<!-- 引入 knife4j 依赖-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -87,7 +87,16 @@
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>${swagger.fox.version}</version> <version>${swagger.fox.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!-- 2.x基于springfox2.x3.x基于springfox3.x-->
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -7,6 +7,7 @@ import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.support.NameUtils; import org.springframework.cloud.gateway.support.NameUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.reactive.config.ResourceHandlerRegistry; import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer; import org.springframework.web.reactive.config.WebFluxConfigurer;
@ -19,6 +20,7 @@ import springfox.documentation.swagger.web.SwaggerResourcesProvider;
* @author bawei * @author bawei
*/ */
@Component @Component
@Primary
public class SwaggerProvider implements SwaggerResourcesProvider, WebFluxConfigurer public class SwaggerProvider implements SwaggerResourcesProvider, WebFluxConfigurer
{ {
/** /**

View File

@ -17,7 +17,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!-- 2.x基于springfox2.x3.x基于springfox3.x-->
</dependency>
<!-- SpringCloud Alibaba Nacos --> <!-- SpringCloud Alibaba Nacos -->
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>

View File

@ -27,3 +27,14 @@ spring:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
rabbitmq: rabbitmq:
host: 124.220.46.186 host: 124.220.46.186
api-docs:
path: v3/api-docs # 指定生成文档的路径,网关会访问这个路径来拉取文档
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.keyl1me.edu.controller # 指定要扫描的包
knife4j:
enable: true # 开启knife4j接口文档美化
setting:
language: zh_cn # 指定语言

22
pom.xml
View File

@ -40,6 +40,8 @@
<poi.version>4.1.2</poi.version> <poi.version>4.1.2</poi.version>
<commons-collections.version>3.2.2</commons-collections.version> <commons-collections.version>3.2.2</commons-collections.version>
<transmittable-thread-local.version>2.13.2</transmittable-thread-local.version> <transmittable-thread-local.version>2.13.2</transmittable-thread-local.version>
<knife4j-spring.version>2.0.9</knife4j-spring.version>
<knife4j-spring-boot.version>2.0.9</knife4j-spring-boot.version>
</properties> </properties>
<!-- 依赖声明 --> <!-- 依赖声明 -->
@ -302,19 +304,31 @@
<version>3.6.0</version> <version>3.6.0</version>
</dependency> </dependency>
<!-- ES官网 驱动包 --> <!--解决集成knife4j时冲突问题-->
<dependency> <dependency>
<groupId>org.elasticsearch.client</groupId> <groupId>com.google.guava</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId> <artifactId>guava</artifactId>
<version>7.17.3</version> <version>20.0</version>
</dependency> </dependency>
<!-- 包含了ui界面 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!-- 2.x基于springfox2.x3.x基于springfox3.x-->
<version>${knife4j-spring.version}</version>
</dependency>
<!-- 商品服务缓存 --> <!-- 商品服务缓存 -->
<dependency> <dependency>
<groupId>com.bawei</groupId> <groupId>com.bawei</groupId>
<artifactId>bawei-mall-product-cache</artifactId> <artifactId>bawei-mall-product-cache</artifactId>
<version>3.6.0</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>