zoukankan      html  css  js  c++  java
  • spring测试从application.properties获取自定义属性

    一、首先引入spring test依赖

    <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.4.4</version>
        </dependency>

    二、application.properties

    zookeeper.master.key=/master
    zookeeper.worker.key=/workers

    三、测试类

    package org.example;
    
    import org.example.master.init.ZKPath;
    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;
    
    /**
     * @Author : wangbin
     * @Date : 2021/4/28 11:55
     */
    
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = ZKPath.class)
    public class Test1 {
        @Autowired
        private ZKPath zkPath;
    
        @Test
        public void test1() {
            System.out.println(zkPath.getMasterKey());
            System.out.println(zkPath.getWorkerKey());
        }
    }
  • 相关阅读:
    display ntp-service sessions
    display ntp-service status
    MySQL与telnet安装
    YL_组播_IGMPv2-v3
    YL_组播_PIM-DM协议原理
    YL_组播_IGMP协议原理
    IIS发布站点问题
    css 定位及遮罩层小技巧
    MYSQL查询某字段中以逗号分隔的字符串的方法
    零度
  • 原文地址:https://www.cnblogs.com/wangbin2188/p/14713611.html
Copyright © 2011-2022 走看看