SpringBoot

SpringBoot

				SpringBoot是Spring和SpringMVC的整合升级体,利用注解来完成Spring和SpringMVC的大部分配置,省略了大量配置文件代码。
				SpringBoot自带tomcat组件,因此这个功能可省略。
  1. 新建maven项目Test_Shop_SpringBoot
    修复JDK版本问题
    修复web.xml骨架版本
  2. 复制pom文件
    定义Spring组件的统一版本,会自动下载Spring和SpringMVC相关jar包
    在这里插入图片描述
  3. 更新maven
    在这里插入图片描述
  4. 复制Shop项目的相关资源代码 (Test_Shop_SpringBoot模板资源)
    注意分目录放置
  5. SpringBoot配置文件
    由于合并了Spring和SpringMVC的功能,因此不在需要这个框架的配置文件,仅需求准备SpringBoot的配置文件application.yml
    复制样板application.yml到 src/main/resources
    在这里插入图片描述
  6. 启动类 BootApplication.java
    由于SpringBoot自带tomcat功能,那么就不能在Tomcat Server来添加项目和启动项目。因此需求一个特殊的类—SpringBoot的启动类,这个类是SpringBoot的启动入口,可以理解这个类就像一个main方法一样,常规启动时附带启动tomcat组件。
    BootApplication.java启动时,会自动加载当前目录及其子目录下的所有类,因此需要把这个启动类放在项目的根目录下。
    在这里插入图片描述
  7. clean项目,maven update,启动BootApplication.java

在这里插入图片描述
SpringBoot工作流程:
1. 手动运行启动类BootApplication.java,同时启动内置tomcat
2. 注解 @MapperScan(“com.xly.dao”)
在这里插入图片描述
读取到dao层
3. 加载配置文件,读取端口号,建立JDBC连接,读取到dao的Mapper配置文件等其它配置
4. dao层之后的Service,Controller正常走Spring加载流程
5. Service自动装配记录dao层;Controller自动装配记录Service层
6. Controller连接到前端资源,完成页面展示

其它功能:
开发模式
true: 启用有更新自动重启功能
false: 关闭有更新自动重启功能

在这里插入图片描述
SpringBoot Junit测试
模板
package com.xly.test;

import java.io.IOException;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.xly.entity.Product;
import com.xly.service.ProductService;

@RunWith(SpringRunner.class)
@SpringBootTest
public class BaseSpringBootTest {

	@Autowired
	private ProductService productService;
	
	@Test
	public void test() throws IOException{
		System.out.println("spring boot testing");
		List<Product> list = productService.selectAll();
		System.out.println(list);
	}
}

日志功能
模板
在这里插入图片描述
启动fastJson
默认Spring使用jackJson来转换,在SpringBoot下启用fastJson

  1. 确保导入fastJson依赖
    在这里插入图片描述
  2. 在启动类配置,额外添加以下代码

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值