您好,欢迎来到宝玛科技网。
搜索
您的当前位置:首页Springboot yaml文件属性自动注入

Springboot yaml文件属性自动注入

来源:宝玛科技网

yaml文件配置

engine:
  path:
    happarserPath: D:\\IdeaProjects\\tool.jar
    jadxPath: D:\\IdeaProjects\\jadx.bat

实体类,用于注入yaml中的属性

@Component
@ConfigurationProperties(prefix = "engine.path")
public class ConfigLoad {
    private String happarserPath;
    private String jadxPath;
...//这里省略Getter,Setter方法

}

测试类

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;

import com.utils.ConfigLoad;

/**
 * 功能描述
 *
 * @author r30002879
 * @since 2020-05-12
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigLoadTest {
    @Autowired
    private ConfigLoad configLoad;

    @Test
    public void propertiesLoad() {
        System.out.println("-----------------------------------------------------------------------");
        System.out.println(configLoad.getHapparserPath());
        System.out.println("-----------------------------------------------------------------------");
    }
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baomayou.com 版权所有 赣ICP备2024042794号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务