Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knife4j文档请求异常 #749

Closed
tangrufeii opened this issue Mar 14, 2024 · 2 comments
Closed

knife4j文档请求异常 #749

tangrufeii opened this issue Mar 14, 2024 · 2 comments

Comments

@tangrufeii
Copy link

网页控制台错误

图片

后端控制台报错

2024-03-14 10:43:28.038 [http-nio-8899-exec-10] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/](DirectJDKLog.java:175)(DirectJDKLog.java:175- Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed: java.lang.StackOverflowError] with root cause 
java.lang.StackOverflowError: null
	at com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.tryToDrainBuffers(PrivateMaxEntriesMap.java:378)
	at com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.drainOnReadIfNeeded(PrivateMaxEntriesMap.java:358)
	at com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.afterRead(PrivateMaxEntriesMap.java:315)
	at com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.get(PrivateMaxEntriesMap.java:622)
	at com.fasterxml.jackson.databind.util.LRUMap.get(LRUMap.java:63)
	at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1468)
	at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1401)
	at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:752)

Springboot版本

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

knife4j版本

  <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
            <version>4.4.0</version>
        </dependency>

yml配置

# Tomcat
server:
  port: 8899
#spring
spring:
  datasource:
    #引用项目中的数据库文件
          type: com.zaxxer.hikari.HikariDataSource
          driver-class-name: org.sqlite.JDBC
          url: jdbc:sqlite:${user.home}/Documents/Atelier/Database/hyway.db
    #        url: jdbc:sqlite:D:\\code2\\ParseJsonToXML\\src\\main\\resources\\static\\sqlite\\hyway.db?date_string_format=yyyy-MM-dd HH:mm:ss
          username: root
          password: 123456
  thymeleaf:
    cache: false
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
# 指定静态资源的路径
web:
resources:
  static-locations:classpath:/static/
# MyBatis Plus配置
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 开启sql日志
    map-underscore-to-case: true # 开启驼峰映射(mp默认开启)
  # 搜索指定包别名
  typeAliasesPackage: com.hyway.**.domain
  # 配置mapper的扫描,找到所有的mapper.xml映射文件
  mapperLocations: classpath*:mapper/**/*Mapper.xml
  # 全局配置
  global-config:
    #刷新mapper
    refresh-mapper: true
# Swagger配置# MyBatis配置
mybatis:
  # 搜索指定包别名
  typeAliasesPackage: com.hyway.**.domain
  # 配置mapper的扫描,找到所有的mapper.xml映射文件
  mapperLocations: classpath*:mapper/**/*Mapper.xml
  # 加载全局的配置文件
  configLocation: classpath:mybatis/mybatis-config.xml
## Swagger配置
springdoc:
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    #operations-sorter: order
  api-docs:
    path: /v3/api-docs
  group-configs:
    - group: 'default'
      paths-to-match: '/**'
      packages-to-scan: com.hyway
  default-flat-param-object: true
knife4j:
  enable: true
  setting:
    language: zh_cn
    swagger-model-name: 实体类列表
  documents: #文档补充说明
    - name: MarkDown语法说明
      locations: classpath:markdown/*
      group: default
    - name: 补充文档
      locations: classpath:markdown1/*
      group: default
  basic: #权限访问设置
    enable: false #默认不开启登陆校验
    username: root
    password: 123456
api:
  title: 自定义 API 文档标题 # 这里设置 API 文档的标题,如果不设置,默认为 'API Documentation'
  version: 2.0 # 设置 API 文档的版本,如果不设置,默认为 '1.0'
  description: 这是个自定义的 OpenAPI 文档描述 # 设置 API 文档的描述,如果不设置,默认为 'OpenAPI Documentation'
  termsOfServiceUrl: https://example.com/terms # 设置 API 文档的服务条款 URL,如果不设置,默认为空
  license:
    name: 自定义许可证名称 # 设置 API 文档中显示的许可证名称,如果不设置,默认为 'name'
    url: https://example.com/license # 设置 API 文档中许可证的 URL,如果不设置,默认为 'url'
  contact:
    name: 作者名称
    url: http://作者的个人网站或公司网站
    email: 作者的电子邮件地址

swagger配置

package com.hyway.config.swaggerConfig;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类用于设置和定制 Swagger/OpenAPI 文档。
 * 通过外部配置文件(如 application.properties 或 application.yml),
 * 可以定制 API 文档的标题、版本、描述、服务条款的 URL 以及许可证信息。
 * 如果没有在配置文件中指定这些值,将使用默认值。
 */
@Configuration
public class SwaggerConfig {

    // API 文档的标题,默认为 "API Documentation"
    @Value("${api.title:API Documentation}")
    private String apiTitle;

    // API 文档的版本,默认为 "1.0"
    @Value("${api.version:1.0}")
    private String apiVersion;

    // API 文档的描述,默认为 "OpenAPI Documentation"
    @Value("${api.description:OpenAPI Documentation}")
    private String apiDescription;

    // API 文档的服务条款的 URL,默认为空
    @Value("${api.termsOfServiceUrl:duck.vin}")
    private String apiTermsOfServiceUrl;

    // API 文档的许可证名称,默认为 "name"
    @Value("${api.license.name:name}")
    private String apiLicenseName;

    // API 文档的许可证 URL,默认为 "url"
    @Value("${api.license.url:url}")
    private String apiLicenseUrl;
    // 添加作者信息的配置
    @Value("${api.contact.name:作者名}")
    private String apiContactName;

    @Value("${api.contact.url:作者网址}")
    private String apiContactUrl;

    @Value("${api.contact.email:作者电子邮箱}")
    private String apiContactEmail;

    /**
     * 创建自定义的 OpenAPI 对象。
     * 使用 @Value 注解注入的值来定制 OpenAPI 文档的基本信息,
     * 包括标题、版本、描述、服务条款 URL 和许可证信息。
     * 这些值可以通过外部配置文件设置,以适应不同项目的需求。
     *
     * @return 定制的 OpenAPI 对象
     */
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title(apiTitle)
                        .version(apiVersion)
                        .description(apiDescription)
                        .termsOfService(apiTermsOfServiceUrl)
                        .contact(new Contact()
                                .name(apiContactName)
                                .url(apiContactUrl)
                                .email(apiContactEmail))
                        .license(new License()
                                .name(apiLicenseName)
                                .url(apiLicenseUrl)));
    }
}

WebMvcConfigurationSupport配置

package com.hyway.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport {



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置拦截器访问静态资源

        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
@tangrufeii
Copy link
Author

问题已解决,排查到最后,即使是最不可能的结果,也只能是真相了,不过具体为什么会导致,暂时还不清楚

public class Page extends Model<Page> {   //问题出自这个实体类,不去继承mybaties-plus的 Model类即可
    @TableId(type = IdType.AUTO)

    private Integer id;

    private String content;
    private String projectPath;

    private Integer fileType;
}

@xiaoymin
Copy link
Owner

估计是springdoc递归解析的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants