系列博客目录
文章目录
- 系列博客目录
- 导致了Swagger没法用了并且导致拦截器不可以使用了
导致了Swagger没法用了并且导致拦截器不可以使用了
sky-take-out的pom.xml修改如下
<!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-spring-boot-starter</artifactId>-->
<!-- <version>${knife4j}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
sky-server的pom.xml修改如下:
<dependency>
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-spring-boot-starter</artifactId>-->
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
WebMvcConfiguration类的修改如下
package com.sky.config;
import com.sky.interceptor.JwtTokenAdminInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
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.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
/**
* 配置类,注册web层相关组件
*/
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
@Autowired
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
/**
* 注册自定义拦截器
*
* @param registry
*/
protected void addInterceptors(InterceptorRegistry registry) {
log.info("开始注册自定义拦截器...");
registry.addInterceptor(jwtTokenAdminInterceptor)
.addPathPatterns("/admin/**")
.excludePathPatterns("/admin/employee/login");
}
/**
* 通过knife4j生成接口文档
* @return
*/
// @Bean
// public Docket docket() {
// log.info("准备生成接口文档...");
// ApiInfo apiInfo = new ApiInfoBuilder()
// .title("臧超禹的苍穹外卖项目接口文档")
// .version("2.0")
// .description("苍穹外卖项目接口文档")
// .build();
// Docket docket = new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo)
// .select()
// .apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
// .paths(PathSelectors.any())
// .build();
// return docket;
// }
/**
* 设置静态资源映射
* @param registry
*/
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
log.info("开始设置静态资源映射...");
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
添加配置
# springdoc-openapi项目配置
springdoc:
swagger-ui:
path: /swagger-ui.html
tags-sorter: alpha
operations-sorter: alpha
api-docs:
path: /v3/api-docs
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: com.sky.controller#注意修改
# knife4j的增强配置,不需要增强可以不配
knife4j:
enable: true
setting:
language: zh_cn
注意:
之后导入代码时候发现问题:MyBatis 解析 CategoryMapper.xml 失败,原因是找不到 Category 类。
原因:MyBatis 配置问题CategoryMapper.xml 中的 typeAlias 或 resultType 的定义有误,导致 MyBatis 解析失败。
sky-take-out\sky-server\src\main\resources\application.yml添加配置type-aliases-package: com.sky.entity
mybatis-plus: # mybatis-plus的配置
# 默认位置 private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};
mapper-locations: classpath:/mapper/*.xml
type-aliases-package: com.sky.entity