问题
:::info
Knife4j Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException
:::
解决
https://zhuanlan.zhihu.com/p/447338078
如果你在启动项目的时候抛出:Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException
千万不要慌,那是因为你的 springboot 版本太高,应该是 2.6.x,由于Springfox使用的路径匹配是基于AntPathMatcher,而Spring Boot 2.6.X使用的是PathPatternMatcher,所以将MVC的路径匹配规则改成 AntPathMatcher,在配置文件中加入如下参数即可(如果没有报错,可以跳过这个环节)
spring:
mvc:
pathmatch:
# Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher
# 所以需要配置此参数
matching-strategy: ant_path_matcher
模版
package generator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import org.apache.ibatis.jdbc.ScriptRunner;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.SQLException;
/**
* <p>
* 快速生成
* </p>
*
* @author lanjerry
* @since 2021-09-16
*/
public class MP {
/**
* 数据源配置
*/
private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
.Builder("jdbc:mysql://z.xxx.cn:3309/glxy?serverTimezone=Asia/Shanghai", "root", "imZyq.");
/**
* 执行 run
*/
public static void main(String[] args) throws SQLException {
FastAutoGenerator.create(DATA_SOURCE_CONFIG)
// 全局配置
.globalConfig(builder -> {
builder.author("zyq") // 设置作者
.enableSwagger() // 开启 swagger 模式
.outputDir("/Users/izyq/Documents/Code/Java/gulixueyuan/service/edu/src/main/java"); // 指定输出目录
})
// 包配置
.packageConfig((scanner, builder) -> builder.parent(scanner.apply("请输入包名")))
// 策略配置
.strategyConfig((scanner, builder) -> builder.addInclude(scanner.apply("请输入表名,多个表名用,隔开")))
/*
模板引擎配置,默认 Velocity 可选模板引擎 Beetl 或 Freemarker
.templateEngine(new BeetlTemplateEngine())
.templateEngine(new FreemarkerTemplateEngine())
*/
.execute();
}
}