1. 创建项目
2. 设置 url
url 修改为 start.aliyun.com/\
https://start.aliyun.com/
3. 设置 项目名 和 java 版本
java 版本选为 8
4. 勾选依赖
勾选常用依赖:
web -> spring web
nosql -> redis
sql -> spring jpa + mysql
5. 修正 mysql 依赖版本
创建项目后,下载依赖可能会报错:
Could not find artifact com.mysql:mysql-connector-j:pom:unknown in alimaven
这主要是 mysql依赖没有指定版本, 需要修改 pom.xml, 添加 mysql 版本
6. 修改文件编码
当进入项目编辑文件时,可能出现乱码现象,这时需要:
- 修改文件编码
文件 -> 设置 -> 编辑器 -> 文件编码
- 修改编译器编码
文件 -> 设置 -> 构建、执行、部署 -> 编译器 -> java 编译器
7. 配置setting.xml
如果不配置setting.xml 的话,下载mvn依赖会非常慢
7.1 创建setting.xml
选中项目目录,点击鼠标右键
7.2 配置阿里云国内镜像源
【设置Maven镜像库为[阿里云镜像]库和Junit镜像库】
填充以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<!-- <mirror>-->
<!-- <id>mirrorId</id>-->
<!-- <mirrorOf>repositoryId</mirrorOf>-->
<!-- <name>Human Readable Name for this Mirror.</name>-->
<!-- <url>http://my.repository.com/repo/path</url>-->
<!-- </mirror>-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>uk</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>nexus</id>
<name>internal nexus repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- junit镜像地址 -->
<mirror>
<id>junit</id>
<name>junit Address/</name>
<url>http://jcenter.bintray.com/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- <mirrors>-->
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<!--This sends everything else to /public -->
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>osc</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.oschina.net/content/groups/public/</url>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<mirror>
<id>net-cn</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.net.cn/content/groups/public/</url>
</mirror>
<mirror>
<id>ui</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>JBossJBPM</id>
<mirrorOf>central</mirrorOf>
<name>JBossJBPM Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</mirror>
</mirrors>
</settings>
7.3 重新加载依赖
8.配置自动导入依赖包
- 操作路径:
文件->设置->编辑器->常规->自动导入->勾选
显示自动导入类
->粘贴时自动导入
->动态添加明确的import
9. 创建配置文件
/src/main/resources/application.yaml
server:
port: 8080
spring:
application:
name: test-spring
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.88.151:3306/test-spring?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: root
jpa:
properties:
hibernate:
hbm2ddl:
auto: update
dialect: org.hibernate.dialect.MySQL57InnoDBDialect