@ConditionalOnProperty 可用来 Mock 测试数据
示例:在 com.xx.xx.pet.test = true 时 使用 mock 数据
定义一个接口
public interface IProductUtils {
public Object queryProductList(String deviceId);
}
该接口有两个实现类
@Service
@ConditionalOnProperty(value = {
"com.xx.xx.pet.test"
}, havingValue = "true")
public class ProductUtilsMock implements IProductUtils {
public Object queryProductList(String deviceId) { // return mock data }
}
@Service
@ConditionalOnProperty(value = {
"com.xx.xx.pet.test"
}, havingValue = "false")
public class ProductUtils implements IProductUtils {
public Object queryProductList(String deviceId) { // return real data }
}
来源:CSDN
作者:Zonson9999
链接:https://blog.csdn.net/wuzhong8809/article/details/103985357