idea 使用spring maven的过程
前言
文章参考多人的博客,已注明
一、新建项目
1.新建项目,spring initializr next
2.设置名称等 next
3.选择工具
4.名称,存储位置
finish 完成新建
二、错误
1.Error:java: 错误: 不支持发行版本 5
此处改成自己电脑上的java的版本即可
2.Error:(3, 32) java: 程序包org.springframework.boot不存在
解决方案:
3.运行后,加载依赖包;
比较缓慢
采用阿里云的镜像来完成:
步骤一:overide打勾
步骤二:在上图的这个路径下的settings.xml文件中加入一下内容(这个文件可能不存在,则新建):
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
步骤三:重新打开idea,再次运行即可;
但是我在这种情况下仍然不行,报类似如下错误
Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.4.RELEASE from/to alimaven (https://maven.aliyun.com/repository/central): PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
解决方案:
1.在画圈处加入如下代码:应用并保存
-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
2.打开右侧的maven,点击clean,然后再次尝试运行程序即可;
(原博客的方式是:clean, complier, install)
原博客:https://blog.csdn.net/xxaann/article/details/104794669
三、项目配置
1.改为.yml文件(可以不改,只要语法正确)
2.test部分运行时出现如下错误:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project demo: There are test failures.
Please refer to E:\study-tool\IdeaProjects\demo\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
1.查看标红目录下的错误信息,
如果自己的数据库是mysql8.0,则错误原因是时区问题:
将java中的url,将时区修改为UTC
url: jdbc:mysql://localhost:3306/ycs?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true
原博客:https://blog.csdn.net/starlemon2016/article/details/90314649