• SpringBoot单元测试与Idea热部署、读取配置文件


    一、乱码解决

    二、单元测试

    三、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桌的Filë́->̓Settings̈́配置文件中->Compiler设置(或者File->Other Settings->Default Settings->Compiler)

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

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

    四、springboot配置文件读取属性

     

  • 相关阅读:
    排序
    git常用操作_分支合并_新建工程等
    ibatis 中调用存储过程
    IDEA试用期结束激活问题
    kafka本地工程的调用说明
    python yield 和 yield from用法总结
    ubuntu14.06 Lts开启ssh服务
    QT-1-环境搭建QT5.4.1&MinGW4.9.1
    虚拟机Ping不通主机解决
    CRC类(处理ITU表)
  • 原文地址:https://www.cnblogs.com/niunafei/p/13195731.html
Copyright © 2020-2023  润新知