SpringBoot快速入门-环境搭建(eclipse)

这里我写一下SpringBoot的环境搭建和创建方法

这里我使用的是eclipse的讲解

首先我们需要去新建一个maven project

我们先看一下目录结构是完整的

之后我们去打开pom文件去看一下最初的pom文件是这样的

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.msfh.springboot</groupId>
  <artifactId>springboot2</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>

之后我们去添加一下SpringBoot的起步依赖

SpringBoot要求,项目要继承SpringBoot的起步依赖spring-boot-starter-parent
 

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
</parent>

SpringBoot要集成SpringMVC进行Controller的开发,所以项目要导入web的启动依赖
 

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

添加之后是这样的

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.1.RELEASE</version>
	</parent>

	<groupId>com.msfh.springboot</groupId>
	<artifactId>springboot2</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>
</project>

最后我们去编写SpringBoot引导类

要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问

这里我们需要注意的事是我们需要在类前给加上SpringBootapplication的注解让他知道这是一个SpringBoot的启动引导

package com.msfh.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
//声明该类是一个SpringBoot引导类,同时可以理解为这是一个入口
public class MySpringBootApplication {
	//main是java程序的入口
	public static void main(String[] args) {
		//run 方法表示运行SpringBoot的引导类 run参数就是SpringBoot引导类的字节码对象
		SpringApplication.run(MySpringBootApplication.class);
	}

}

然后我们去启动测试一下

出现这个页面代表环境搭建已经完成了

发布了52 篇原创文章 · 获赞 85 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_34037264/article/details/104296904
今日推荐