Springboot开篇

1.Spring -boot-starter-web:用于构建web 应用模块,加入后包含spring mvc框架,默认内嵌tomcat容器

2.spring-boot-starter-jpa:用于构建spring -data jpa应用,使用hibernate 作为orm框架

3.spring-boot-starter-mongodb :用于构建spring data mongodb应用,底层使用mongodb驱动操作mongodb数据库

4.spring-boot-starter-redis :用于构建sping data redis应用,使用jedis操作redis数据库。

5.spring-boot-thymeleaf:构建一个使用thymeleaf作为视图web应用。

6.spring-boot-starter-test:顾名思义,主要用于单元测试。

spring-boot 构建使用maven,或者gradle.

1.新建maven项目,勾选create a simple project

Springboot开篇

2.点击next

 Springboot开篇

groupid和artifactId被统称为“坐标”是为了保证项目唯一性而提出的,如果你要把你项目弄到maven本地仓库去,你想要找到你的项目就必须根据这两个id去查找。
groupId一般分为多个段,这里我只说两段,第一段为域,第二段为公司名称。域又分为org、com、cn等等许多,其中org为非营利组织,com为商业组织。举个apache公司的tomcat项目例子:这个项目的groupId是org.apache,它的域是org(因为tomcat是非营利项目),公司名称是apache,artigactId是tomcat。
原文链接:https://blog.****.net/tangweiee/article/details/77931537

src/main/java用于存放主应用程序的类。

src/main/resources/用于存放主应用程序的资源文件。

src/test用于存放测试相关的java类和资源。

pom.xml则时的构建脚本。

一般情况下,maven脚本文件需要继承“spring-boot-starter-parent”项目,修改pom.xml文件。

<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>cn.mhy</groupId>
  <artifactId>first-boot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <!-- 继承spring boot starter -->
  <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.1.RELEASE</version>
  </parent>
  <!-- 继承web starter的依赖 -->
  <dependencies>
  	<dependency>
  		<groupId>org.springframework.boot</groupId>
  		<artifactId>spring-boot-starter-web</artifactId>
  	</dependency>
  </dependencies>
</project>

  如果加入依赖后,eclipse中的maven存在错误,可以选中项目,鼠标右击,在弹出的菜单栏中选择-maven-update project命令来解决问题。

接下来,编写启动类:

@SpringBootApplication
public class FistApp {
	public static void main(String args[]) {
		SpringApplication.run(FistApp.class, args);
	}

}

  

@SpringBootApplication注解,该注解声明该类是一个Spring boot应用。
如果注释掉@springBootApplication注解,那么运行就会报错。
@SpringBootApplication需要标注在某个类中,说明这个类是springboot的主配置类,springboot应该运行该类的main方法。
该注解具有
@SpringBootConfigure、
@EnableAutoConfigure、
@CompoentScan等注解得功能。
myApplication.FistApp                    : Started FistApp in 2.816 seconds (JVM running for 3.224)

  看到这 个信息,可知tomcat启动端口8080,打开http:localhost:8080

Springboot开篇

 表示应用已经成功启动。