以前在开发springboot项目时候使用SpringBootTest总是出问题,然后就放弃了,最近测试又成功了,所以记录一下
废话不多说上代码...
package com.hhmt.delivery;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DeliveryApplicationTests {
@NacosValue("${ocpx.domain}")
private String domain;
@Test
public void testDomain() {
System.out.println(domain);
}
}
多环境通过
@ActiveProfiles("dev") 指定环境