test:
username: admin
password: 12345
创建config 模型:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class YxConfig {
public static String username;
public static String password;
public static boolean isActive;
@Value("${test.username}")
public void setUsername(String param) {
username= param;
}
@Value("${test.passwordt}")
public void setPassword(String param) {
password= param;
}
}
@RunWith(SpringRunner.class)
@SpringBootTest
public class YxConfigTest {
@Test
public void test() {
System.out.print("username:" + YxConfig.username+ "; ");
System.out.print("password:" + YxConfig.password+ "; ");
}
}
这样就可以读取配置文件的vlaue,后续如果有其它方法再进行补充