package com.ruoyi; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import lombok.Data; @Component @ConfigurationProperties(prefix = "ruoyi") @Data public class ProDemo { private String profile; }
package com.ruoyi; 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; @RunWith(SpringRunner.class) @SpringBootTest public class TestBoot { @Autowired private ProDemo pro; @Test public void doTest() { System.err.println("xxx" + pro.getProfile()); } }
读取配置文件,方法2:
@Value("${ruoyi.port}") private Integer port;
springboot
原文:https://www.cnblogs.com/argor/p/12380986.html