首页 > 编程语言 > 详细

SpringBoot单元测试与Idea热部署

时间:2020-06-26 18:59:12      阅读:118      评论:0      收藏:0      [点我收藏+]

一、乱码解决

二、单元测试

三、idea中springboot热部署

四、springboot配置文件读取属性

 

一、乱码解决

  方式一 、

   @RequestMapping(value = "/demo", produces = "application/json;charset=utf-8")

  方式二、

# 设置utf-8,
spring.http.encoding.force-response=true

     项目一般配置server.tomcat.uri-encoding=utf-8

二、单元测试

引入pom.xml 依赖

      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

编写测试类注意@SpringBootTest与@RunWith配合

package city.albert.springboot01;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
* @SpringBootTest 注解表明是springboot的测试类需要加载applicationContext的上下文
* @RunWith 启动测试类,SpringRunner.class 指定springboot方式加载
*/
@SpringBootTest
@RunWith(SpringRunner.class)
class Springboot01ApplicationTests {

@Test
void contextLoads() {
//业务测试
}
}

三、idea中springboot热部署

1、引入pom文件,devtools是springboot的热部署包

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>

2.idea配置

idea桌的File?->?Settings?配置文件中->Compiler设置(或者File->Other Settings->Default Settings->Compiler)

技术分享图片

 

 然后点击下面的apply 进行配置生效,然后点击ok

技术分享图片

 

使用快捷键“Ctrl+Shift+Alt+/” 选择Maintenance中的选项框Registry然后确认,如下图,勾选compiler.automake.allow.when.app.running,然后在close

技术分享图片

 

四、springboot配置文件读取属性

技术分享图片

技术分享图片

 

 

 

 

SpringBoot单元测试与Idea热部署

原文:https://www.cnblogs.com/niunafei/p/13195731.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!