【Spring Boot 项目创建】001-Spring Boot 项目创建、项目的初始化配置

一、Spring Boot 项目创建

1、新建 Spring Boot 项目

1.1 方式一:通过官网

此种方式不常用,学这么久 Spring Boot 了,我都是使用 IDEA 创建的!

官网地址

https://start.spring.io/

创建截图

image-20210623223204021

1.2 方式二:通过 IDEA 创建

第一步:创建项目

image-20210623223606915

第二步:配置项目

image-20210623223711757

第三步:选择需要的依赖

image-20210623223854959

第四步:项目创建完成

image-20210623223922797

第五步:最终项目结构

image-20210623225743209

第六步:修改版本号为2.4.0

为了跟讲师保持一致,等后面熟悉了可使用更新的版本!下面是 pom.xml 部分内容截取!2.4.0 为版本号!

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

1.3 Spring Boot 项目的一些补充信息

Spring Boot 项目不需要配置容器,是因为使用了嵌入式容器,默认使用 tomcat 启动,默认端口号是 8080 ,当然也可以使用传统的方式,达成 war 包,放入单独的 tomcat 中运行!

Spring Boot 项目使用 main() 函数启动,一般放在 XXXApplication 中,需要加 @SpringBootApplication 注解,

2、项目的初始化配置

2.1 编码全部配置为 UTF-8

File Encodings

image-20210623230551921

SSH Terminal

image-20210623230628135

2.2 配置 JDK

image-20210623231008748

2.3 配置 Maven

很简单的配置,可以使用 IDEA 默认的,我这里配置的是自己下载的,使用起来没啥区别!

image-20210623231204671

settings.xml 文件是重点,里面配置了阿里云镜像,下面分享两个配置,第一个是我之前搜集的,第二个是老师的

<?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">
  <!--这个是本地仓库地址-->
  <localRepository>D:\MySoft\Maven\repository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  </servers>
  <!--下面 mirror 是重点,是各个国内的镜像源-->
  <mirrors>
	 <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://192.168.1.100:8081/nexus/content/groups/public/</url>-->
	     <url>http://repo.maven.apache.org/maven2</url>
	     <mirrorOf>central</mirrorOf>
	 </mirror>
  </mirrors>
  <profiles>
	<profile>
	
	<id>jdk-1.8</id>    
	
	    <activation>  
	
	        <activeByDefault>true</activeByDefault>    
	        <jdk>1.8</jdk>    
	    </activation>    
	    <properties>    
	        <maven.compiler.source>1.8</maven.compiler.source>    
	        <maven.compiler.target>1.8</maven.compiler.target>    
	        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
	    </properties>    
	</profile>
  </profiles>
</settings>

下面这个是老师的,发现老师好像更强,我换成老师的吧。。。哈哈哈!

<?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">
    <localRepository> 这里是地址,注意改成自己的本地 Maven 仓库地址 </localRepository>

    <pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>
    <servers>
    </servers>

    <mirrors>
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central</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>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2</url>
            <mirrorOf>central</mirrorOf>
        </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>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>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>

        <!-- 中央仓库在中国的镜像 -->
        <mirror>
            <id>maven.net.cn</id>
            <name>one of the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
        <profile>
            <id>repository_set</id>
            <repositories>
                <repository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>public</id>
                    <name>Public Repository</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <releases>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>public</id>
                    <name>Public Repository</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>

    </profiles>

</settings>

2.4 配置 Git

第一步:确保本机安装了 git

image-20210623233103848

第二步:启用版本控制

image-20210623232427496

第三步:第一次提交

刚下载 git 的话,可能需要配置用户名和邮箱

image-20210623233510271

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值