htmledit_views">
springboot3 集成knife4j 访问页面:http://127.0.0.1:8022/doc.html 提示: No endpoint GET /doc.html.
描述环境:
java17
springboot3.2.0
knife4j的jar包
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId><version>4.4.0</version></dependency>
解决办法:
设置静态资源映射
继承WebMvcConfigurationSupport ,实现addResourceHandlers方法
完整代码如下:
package com.demo2.config;import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlow;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;/*** <p>Swagger 配置类</p>** @author By: chegnxuyanshitang* Package com.demo2.config* Ceate Time 2024-04-22 10:25*/
@Configuration
public class Swagger3Config extends WebMvcConfigurationSupport {/*** 设置静态资源映射** @param registry*/protected void addResourceHandlers (ResourceHandlerRegistry registry) {registry.addResourceHandler ("/doc.html").addResourceLocations ("classpath:/META-INF/resources/");registry.addResourceHandler ("/webjars/**").addResourceLocations ("classpath:/META-INF/resources/webjars/");}@Beanpublic OpenAPI apiInfo () {return new OpenAPI ().info (new Info ().title ("demo服务").version ("1.0.0").description ("demo接口").license (new License ().name ("Apache 2.0").url ("http://www.yang.com/")));}
}
再次访问:
http://127.0.0.1:8022/doc.html