首页 > 移动平台 > 详细

spring测试从application.properties获取自定义属性

时间:2021-04-28 14:27:18      阅读:27      评论:0      收藏:0      [点我收藏+]

 

一、首先引入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());
    }
}

 

spring测试从application.properties获取自定义属性

原文:https://www.cnblogs.com/wangbin2188/p/14713611.html

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