1. SpringBoot简化开发
1.1 parent
parent定义了若干个坐标版本号,完成依赖管理 。parent是为了防止依赖冲突定义的,并没有直接引入依赖。
1.2 Starter
Starter定义了当前项目使用的所有依赖坐标,使得我们可以减少依赖配置工作。
1.3 引导类
SpringBoot开发的主类,也就是这个类 , 是一个引导类,她是SpringBoot工程的执行入口。类运行后,会初始化Spring容器,扫描引导类所在包加载bean 。
1.4 内嵌Tomcat
SpringBoot内嵌了三种Web服务器 : Tomcat、Jetty、Undertow 。
2. REST开发风格
REST即表述性状态传递(英文:Representational State Transfer,简称REST)。
REST其实就是访问网络资源的格式。

3. SpringBoot整合Junit :
SpringBoot整合Junit,首先要有SpringBoot项目。
3.1 依赖引入 :
需要在pom.xml导入依赖(也就是spring-boot-starter-test):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
3.2 开始测试过程
导入后,需要在测试类上增加注解 @SpringBootTest 。 实现两个步骤 : 1.注入要测试的对象 。 2.执行注入对象的对应的方法 。
这里提供我写的测试类SpringBootJunitTest.java :
package com.techvc;
import com.techvc.dao.impl.TestJunitDaoImpl;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class SpringBootJunitTest {
// 1.注入要测试的对象
@Autowired
private TestJunitDaoImpl testJunitDaoimpl ;
@Test
public void testSpringBoot(){
// 2.执行注入对象的对应的方法。
testJunitDaoimpl.testGua();
}
}
上边测试类,引入了一个简单的类(直接打印字符串),注意这里使用了@Repository注解来标注这是个springboot管理的类:
package com.techvc.dao.impl;
import com.techvc.dao.TestJunitDao;
import org.springframework.stereotype.Repository;
@Repository
public class TestJunitDaoImpl implements TestJunitDao {
@Override
public void testGua() {
System.out.println("|+||+||+|SpringBootJunit Test GuaGua Wa Wak|+||+||+|");
}
}
网友评论