当前位置:   article > 正文

【Mybatisplus】创建Spring Boot工程打包错误解决方法_the artifact mysql:mysql-connector-java:jar:8.0.31

the artifact mysql:mysql-connector-java:jar:8.0.31 has been relocated to com

目录

打包问题解决方法在文章末尾

 创建Spring Boot工程

a.初始化工程

b.引入依赖

编写代码

a.配置application.yml

了解一下配置application.properties

 application.yml配置

b.启动类

c.创建实体类


 创建Spring Boot工程

a.初始化工程

21f906d75b7746428a9575b759f86da6.png

3d0b12bed0a04cf197d319e7bb286dfe.png fe0ac147c16149cc9c7685b4c95b8b80.png

6f9fa9e37d734549abc3dd3d74b7f790.png 0df186e6c9bf481282d13ee6a74dbbef.png

dependencies:依赖关系 

b.引入依赖

 在pom.xml的dependencies中加入依赖关系

  1. <!--mybaties-plus启动器-->
  2. <dependency>
  3. <groupId>com.baomidou</groupId>
  4. <artifactId>mybatis-plus-boot-starter</artifactId>
  5. <version>3.5.1</version>
  6. </dependency>
  7. <!--lombok用于简化实体类开发-->
  8. <dependency>
  9. <groupId>org.projectlombok</groupId>
  10. <artifactId>lombok</artifactId>
  11. <optional>true</optional>
  12. </dependency>
  13. <!--mysql驱动-->
  14. <dependency>
  15. <groupId>mysql</groupId>
  16. <artifactId>mysql-connector-java</artifactId>
  17. <scope>runtime</scope>
  18. </dependency>

 这里要特别注意我们的springboot工程刚创建的时候是没有添加版本的,有爆红错误,Plugin 'org.springframework.boot:spring-boot-maven-plugin:' not found。8e8516fd91e04ef39d2a1bba4dd4cf12.png

这里只需要加上和开头处和父类版本一样的version即可 a96c4204e86149369cbe119d1ff9c670.png

 然后我们对maven进行刷新,让其安装对应的依赖关系,直到这些爆红的错误消失为止,如果有的错误没有消失(但是我们IDEA中已经安装完了相应的依赖),这个时候我们最好进行重启一下IDEA。

编写代码

cdd2986d5e2245fa927ec78e36f04abe.png

a.配置application.yml

首先区分properties文件和yml文件的不同

properties   使用‘.’来进行分隔                     

yml   使用‘:’来进行分隔

yml中的一些格式比properties的要求要高。

2daf2a29a08b4155be53fef911bb8b58.png

创建application.yml只需要复制application.properties粘贴到resources中然后修改文件名即可。

  1. spring.datasource.type=com.zaxxer.hikari.HikariDataSource
  2. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

了解一下配置application.properties

8.0版本以上的mysql需要引用的Driver是:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

5.0版本以上的mysql需要引用的Driver是:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

查看springboot使用的mysql版本需要在pom.xml中按ctrl打开mysql查看版本

b2467b152c0f49528acceca55ed21456.png

 application.yml配置

02dc01d08aab499e9310f6ef07267220.png

  1. spring:
  2. #配置数据源信息系
  3. datasource:
  4. #配置数据源类型
  5. type: com.zaxxer.hikari.HikariDataSource
  6. driver-class-name: com.mysql.cj.jdbc.Driver
  7. #配置连接数据库的个人信息
  8. url: jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=false
  9. username: root
  10. password: abc123

 SpringBoot 版本低于2.4.3(不含),Mysql驱动版本大于8.0时,需要在url连接串中配置时区,否则会报错java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more

b.启动类

  1. package com.atzeren.mybatiesplus;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class MybatiesplusApplication {
  6. public static void main(String[] args) {
  7. SpringApplication.run(MybatiesplusApplication.class, args);
  8. }
  9. }

c.创建实体类

  1. package com.atzeren.mybatiesplus.pojo;
  2. import lombok.*;
  3. /**
  4. * @Program:mybatiesplus
  5. * @description:pojo
  6. * @author: jiangzeren
  7. * @create: 2022-11-01 16
  8. **/
  9. @Data
  10. public class User {
  11. private Long id;
  12. private String name;
  13. private Integer age;
  14. private String email;
  15. }

打包出错

  1. C:\Users\jiangzeren\.jdks\corretto-1.8.0_342\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\IDEAAA\mybatiesplus "-Dmaven.home=D:\IDEAAA\IntelliJ IDEA 2020.3.4\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\IDEAAA\IntelliJ IDEA 2020.3.4\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=D:\IDEAAA\IntelliJ IDEA 2020.3.4\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\IDEAAA\IntelliJ IDEA 2020.3.4\lib\idea_rt.jar=56330:D:\IDEAAA\IntelliJ IDEA 2020.3.4\bin" -Dfile.encoding=GBK -classpath "D:\IDEAAA\IntelliJ IDEA 2020.3.4\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;D:\IDEAAA\IntelliJ IDEA 2020.3.4\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2020.3.4 compile
  2. [INFO] Scanning for projects...
  3. [INFO]
  4. [INFO] ----------------------< com.atzeren:mybatiesplus >----------------------
  5. [INFO] Building mybatiesplus 0.0.1-SNAPSHOT
  6. [INFO] --------------------------------[ jar ]---------------------------------
  7. [WARNING] The artifact mysql:mysql-connector-java:jar:8.0.31 has been relocated to com.mysql:mysql-connector-j:jar:8.0.31
  8. [INFO]
  9. [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ mybatiesplus ---
  10. [INFO] Using 'UTF-8' encoding to copy filtered resources.
  11. [INFO] Using 'UTF-8' encoding to copy filtered properties files.
  12. [INFO] Copying 2 resources
  13. [INFO] ------------------------------------------------------------------------
  14. [INFO] BUILD FAILURE
  15. [INFO] ------------------------------------------------------------------------
  16. [INFO] Total time: 1.543 s
  17. [INFO] Finished at: 2022-11-01T16:20:17+08:00
  18. [INFO] ------------------------------------------------------------------------
  19. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project mybatiesplus: Input length = 1 -> [Help 1]
  20. [ERROR]
  21. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  22. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  23. [ERROR]
  24. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  25. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  26. Process finished with exit code 1

62de0d7f6d2e4397b892d2c622153666.png

 遇到这一类问题可以参考以下几篇文章Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources_慢来来的博客-CSDN博客_pom文件进入父工程快捷键

看了这几篇博客,发现还是没有什么很大的用处,于是我将尚硅谷的pom.xml打开,复制粘贴到了我的pom.xml中,发现再次刷新maven之后运行成功了。

b5465ea480da4597bbdfaa721a01cbbd.png

 对比代码发现原来是java版本的问题,把java.version改为1.8即可。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.7.5</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.atzeren</groupId>
  12. <artifactId>mybatiesplus</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>mybatiesplus</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-test</artifactId>
  27. <scope>test</scope>
  28. </dependency>
  29. <!--mybaties-plus启动器-->
  30. <dependency>
  31. <groupId>com.baomidou</groupId>
  32. <artifactId>mybatis-plus-boot-starter</artifactId>
  33. <version>3.5.1</version>
  34. </dependency>
  35. <!--lombok用于简化实体类开发-->
  36. <dependency>
  37. <groupId>org.projectlombok</groupId>
  38. <artifactId>lombok</artifactId>
  39. <optional>true</optional>
  40. </dependency>
  41. <!--mysql驱动-->
  42. <dependency>
  43. <groupId>mysql</groupId>
  44. <artifactId>mysql-connector-java</artifactId>
  45. <scope>runtime</scope>
  46. </dependency>
  47. </dependencies>
  48. <build>
  49. <plugins>
  50. <plugin>
  51. <groupId>org.springframework.boot</groupId>
  52. <artifactId>spring-boot-maven-plugin</artifactId>
  53. <version>2.7.5</version>
  54. </plugin>
  55. <plugin>
  56. <groupId>org.apache.maven.plugins</groupId>
  57. <artifactId>maven-resources-plugin</artifactId>
  58. <!--修改版本-->
  59. <version>3.1.0</version>
  60. </plugin>
  61. </plugins>
  62. </build>
  63. </project>

这只是我遇到的问题,仅对我有效,如果你也是jdk版本默认设置为17或者18也可能会产生这个问题,为了验证是不是jdk产生的影响,我又重新将jdk版本设置为了17,发现仍然出现之前的情况。

e1f4f2a78a924850bfd18d7a2627ec02.png

 正确方法打包之后get、set方法、构造器都会自动创建,,这样的话在实际开发过程中我们就不用这么麻烦了。8ff34d573a194ffa85bb2e8155f14251.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/508621
推荐阅读
相关标签
  

闽ICP备14008679号