在用mybatis逆向工程生成代码时报错:
问题描述:
出错显示:
Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project springboot: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate failed: Exception getting JDBC Driver: com.mysql.cj.jdbc.Driver -> [Help 1]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.212 s
[INFO] Finished at: 2020-11-15T09:20:09+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project springboot: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate failed: Exception getting JDBC Driver: com.mysql.cj.jdbc.Driver -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
原因分析:
其实就是版本问题。
这种情况是pom文件的配置错了,是里面的版本问题,由于使用了mysql8.0以上的版本,因此在配置里也要改成8.0的version,而不是5.几的version
正确如下:
解决方案:
将pom文件中mybaitis-connector-core版本更换为8.0.15(只要是8以上的就可以)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mybatis反向生成工程依赖 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
如下截图所所示,pom文件和generatorConfig.xml示
还需要注意
-
**generatorConfig.xml中 ** ,下的 targetProject路径要写对;我原本写的是“项目名/src/main/java/”,出现
The specified target project directory springboot\src\main\resources does not exist
表示生成目录没找到。 -
正确写法应该是
把springboot这个项目名去掉
为
targetProject="src\main\java"
;
最后生成代码如下:
文章错误解决参考
链接:
link
.
版权声明:本文为weixin_42488513原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。