junit中使用 @value

4,177 阅读1分钟

解决方案

第一种

  1. 在test资源文件下,添加配置文件,配置文件的profile定位test(test这个名字自定义)
  2. 在对应的单元测试的类上加上注解@activeProfile(value="test")

第二种

image.png 加上TestPropertySource注解,然后将之前@value映射的路径,写在properties中就可以了

参考