idea 运行 springbootTest测试类 加载 bootstrap和激活的环境ActiveProfiles(“prod“)

package mip.bigdata.cms.service.impl;


import mip.bigdata.cms.Application;
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.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;


@ActiveProfiles("prod")//dev、test等
@RunWith(SpringRunner.class)
@SpringBootTest
//开始的时候环境 变量无法加载 spring.profiles.active=prod;spring.main.allow-bean-definition-overriding=true;jasypt.encryptor.password=smartone-bigdata
//@TestPropertySource("classpath:bootstrap-prod.yaml")
public class MipPostWorksTemplateServiceImplTest {

    @Autowired
    private MipPostWorksTemplateServiceImpl mipPostWorksTemplateService;

    @Test
    public void findTemplateIdsByTags() {
        List<Long> tags = new ArrayList<>();
        List<Long> templateIdsByTags = mipPostWorksTemplateService.findTemplateIdsByTags(tags);
        System.out.println(templateIdsByTags);
    }
}

加载的时候因为环境变量的加载原因:导致 测试类一直不加载 配置文件,或者配置文件报错

这里如果是多个变量 需要在 环境变量中 一个一个的设置,不能整串粘贴进来

比如:--spring.profiles.active=prod --spring.main.allow-bean-definition-overriding=true --jasypt.encryptor.password=smartone-bigdata

粘贴进来是这样的:

 将多个变量合成了一个变量 ,启动命令中是可以这样的,但是环境变量中是不可以的

@SpringBootTest(classes = Application.class) 这里默认就是加载启动类,不写也可以,这样

@SpringBootTest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值