zoukankan      html  css  js  c++  java
  • 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配置文件读取属性

     

  • 相关阅读:
    超能陆战队之大白的制作过程
    React生命周期
    系统环境变量的解析
    React函数组件
    Node Js模块讲解
    封装读取文件(node js)
    思维导图
    《Amazon Aurora: Design Considerations for High Throughput Cloud-Native Relational Databases》论文总结
    《Object Storage on CRAQ: High-throughput chain replication for read-mostly workloads》论文总结
    《 ZooKeeper : Wait-free coordination for Internet-scale systems 》论文研读
  • 原文地址:https://www.cnblogs.com/niunafei/p/13195731.html
Copyright © 2011-2022 走看看