你好,我有一个springboot应用程序,并且有两个可能的弹簧配置文件,一个环境配置相关(dev,prod,staging ...)和一个模拟一些远程服务,我们称之为remoteServiceMock。所以我有一个标明原产服务:@IfProfileValue @IfProfileValue两个弹簧配置文件
@Profile("!remoteServiceMock")
和模拟豆:
@Profile("remoteServiceMock")
一切,除了测试都很好,当我运行的应用程序:
install -Dspring.profiles.active=dev,remoteServiceMock
或
install -Dspring.profiles.active=dev
因此对应丁豆被加载。但是我遇到了测试问题。 我的测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@Category({IntegrationTest.class})
@TestPropertySource("classpath:test.properties")
@IfProfileValue(name = "spring.profiles.active",
values = "remoteServiceMock")
public class DeltaServiceMockTest {
@Autowired
private RemoteService remoteService;
@Test
public void shouldIntiService() throws Exception {
assertNotNull(remoteService);
}
@Test
public void shouldGetMockDelta() throws Exception {
RemoteData remoteDate = remoteService.getData(new Date(), new Date());
assertEquals(15,remoteDate.getActivity().size());
}
}
该测试正在只有spring.profiles.active正好匹配执行的问题。因此,测试将只运行,如果我会写:
@IfProfileValue(name = "spring.profiles.active", = "dev,remoteServiceMock")
的问题是:
1)是否有可能写一些类型的扩展为IfProfileValue与“包含” /“不包含”配置文件功能
2)对于我的目标是否有其他更好的解决方案? (所以我想嘲笑一个(在功能上有几个将)远程服务,并将我的应用程序部署到env)。
感谢
似乎我太困了,并没有找到容易的解决方案跳过,就像这里(http://stackoverflow.com/a/32892291/3502543),但ActiveProfileResolver也适合我:)谢谢很多。 – Maksym