美文网首页
idea springboot test无法获取apollo的e

idea springboot test无法获取apollo的e

作者: 站在海边看远方 | 来源:发表于2021-03-08 17:28 被阅读0次

一个springboot应用,使用到了apollo,需设置vm options,设置env信息和spring profile信息。

这样应用启动的时候就知道获取apollo的具体环境配置和spring要激活的环境信息


image.png

在idea中测试springboot应用的服务,使用junit进行测试,但是并不能获取apollo的env信息。

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ServiceApplication.class)
public class ServiceTest {
}

idea configuration如下


image.png

这样配置无法获取env。

查看apollo获取配置的源码
com.ctrip.framework.foundation.internals.provider.DefaultServerProvider#initEnvType

image.png

env的配置是从vm options中获取的,应该是junit test运行时无法获取到springboot application的vm options信息。

在junit test的配置页面,添加vm options参数,apollo就可以读到env配置了


image.png

相关文章

网友评论

      本文标题:idea springboot test无法获取apollo的e

      本文链接:https://www.haomeiwen.com/subject/kmzpqltx.html