前言

关于spring boot 是什么我就不再啰嗦了,需要了解的同学可以参考这篇文章 spring boot
本篇文章主要记录如何使用IDEA工具创建spring boot项目,以及使用git保存项目

开始创建项目

一 使用IDEA创建spring boot项目
一 使用IDEA创建spring boot项目
一 使用IDEA创建spring boot项目
一 使用IDEA创建spring boot项目
一 使用IDEA创建spring boot项目

maven的设置

如果你发现,下载依赖包时特别的慢,那么我建议你设置一下下载仓库的地址

打开IDEA 的maven设置

我这里是我自己下载 的maven,当然你也可以使用IDEA自带的maven
一 使用IDEA创建spring boot项目

设置自己的setting文件

打开自己的setting.xml文件
找到<profile> 标签 添加多个仓库地址
我推荐阿里云的地址 http://maven.aliyun.com/nexus/content/groups/public/
更多maven资料参考文章 settings-xml-配置详解

·····
·····
<profile>
			
				<repositories>
				········
                <repository>
					<id>nexus</id>
					<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
					<!-- <url>https://repository.apache.org/content/groups/staging/</url> -->
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
				······  
			</repositories>
			<pluginRepositories>
                <pluginRepository>
					<id>nexus</id>
					<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
              ······
			</pluginRepositories>
		</profile>
		·······

一 使用IDEA创建spring boot项目
这样就创建一个项目完成了
试试简单的hello world 看能否正常启动
我们来写个简单的控制器
一 使用IDEA创建spring boot项目
然后启动spring boot
一 使用IDEA创建spring boot项目

在浏览器中访问 http://127.0.0.1:8080/hello
一 使用IDEA创建spring boot项目
OK 创建完成

好玩的日志消息 banner.txt

在resource 目录下添加这个文件,看看启动时有什么变化吧文件下载地址
一 使用IDEA创建spring boot项目

使用git 仓库管理代码(以下为补充内容)

如何使用git不是我要讲的重点,我讲的是已经创建好的项目如何利用IDEA上传到git仓库中
想理解使用git的参考这篇文章
常用的git命令

1. 首先,我们在本地建立仓库,并将项目提交到本地

1.1 我们利用idea新建一个Maven项目(其实随便什么项目都可以).

一 使用IDEA创建spring boot项目

一 使用IDEA创建spring boot项目

这两步操作的意义是在本地(在本项目所在路径)建立一个Git仓库

1.2将本项目添加到本地仓库

我们在项目文件名上右键选择git,通过add添加到本地库的跟踪区,再comment正式提交到本地仓库

至此,在本地建立仓库操作完成。

一 使用IDEA创建spring boot项目

2.建立远程Git仓库。

本实例是在码云上新建项目,其他github、gitlab类似。(效果图如下)

一 使用IDEA创建spring boot项目

3.将本地项目推送到远程仓库

遵循git提交流程,我们需要先pull后push,所以我们需要先在IDEA上设定远程仓库地址

一 使用IDEA创建spring boot项目

将git地址添加进去,之后我们尝试pull拉取远程数据会出现如下错误

Can't Update
			No tracked branch configured for branch master or the branch doesn't exist.
			To make your branch track a remote branch call, for example,

			git branch --set-upstream-to origin/master master (show balloon)

出现这个错误的原因是:本地未建立分支与远程的master分支进行关联

解决办法是在idea左下角的terminal窗口即命令行执行下面代码

git branch --set-upstream-to=origin/master master

我们在继续 git pull 时,还会出现下面异常 :fatal: refusing to merge unrelated histories

原因是:在pull时Git发现是两个不同的项目

解决办法是在idea左下角的terminal窗口即命令行执行下面代码

git pull origin master ----allow-unrelated-histories

最后我们在git pull时发现成功了,最后git push完成。

相关文章: