前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >【Spring Boot 项目创建】001-Spring Boot 项目创建、项目的初始化配置

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

作者头像
訾博ZiBo
发布2025-01-06 18:34:19
发布2025-01-06 18:34:19
22400
代码可运行
举报
运行总次数:0
代码可运行

一、Spring Boot 项目创建

1、新建 Spring Boot 项目

1.1 方式一:通过官网

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

官网地址

https://start.spring.io/

创建截图
image-20210623223204021
image-20210623223204021
1.2 方式二:通过 IDEA 创建
第一步:创建项目
image-20210623223606915
image-20210623223606915
第二步:配置项目
image-20210623223711757
image-20210623223711757
第三步:选择需要的依赖
image-20210623223854959
image-20210623223854959
第四步:项目创建完成
image-20210623223922797
image-20210623223922797
第五步:最终项目结构
image-20210623225743209
image-20210623225743209
第六步:修改版本号为2.4.0

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

代码语言:javascript
代码运行次数: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
image-20210623230551921

SSH Terminal

image-20210623230628135
image-20210623230628135
2.2 配置 JDK
image-20210623231008748
image-20210623231008748
2.3 配置 Maven

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

image-20210623231204671
image-20210623231204671

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

代码语言:javascript
代码运行次数:0
复制
<?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>

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

代码语言:javascript
代码运行次数:0
复制
<?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-20210623233103848
第二步:启用版本控制
image-20210623232427496
image-20210623232427496
第三步:第一次提交

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

image-20210623233510271
image-20210623233510271
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-01-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、Spring Boot 项目创建
    • 1、新建 Spring Boot 项目
      • 1.1 方式一:通过官网
      • 1.2 方式二:通过 IDEA 创建
      • 1.3 Spring Boot 项目的一些补充信息
    • 2、项目的初始化配置
      • 2.1 编码全部配置为 UTF-8
      • 2.2 配置 JDK
      • 2.3 配置 Maven
      • 2.4 配置 Git
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档