1

こんにちは、私は springboot アプリを持っています。2 つの可能性のある spring プロファイルがあります。1 つは環境構成関連 (dev、prod、staging...) で、もう 1 つはリモート サービスをモックしたもので、remoteServiceMock と呼びましょう。だから私はでマークされたオリジンサービスを持っています:

@Profile("!remoteServiceMock")

そして模擬豆:

@Profile("remoteServiceMock")

次のコマンドでアプリケーションを実行すると、テスト以外はすべて問題ありません。

install -Dspring.profiles.active=dev,remoteServiceMock

また

install -Dspring.profiles.active=dev

したがって、対応する Bean がロードされます。しかし、テストで問題が発生しました。私のテストクラス:

@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)私の目標に対する他のより良い解決策はありますか? (したがって、リモートサービスの1つ(機能にはいくつかあります)をモックし、アプリをステージング環境にデプロイしたいと思います)。

ありがとう

4

1 に答える 1

2

機能を調べて@ActiveProfiles、に基づいてカスタマイズすることをお勧めしますActiveProfilesResolver(この Spring ドキュメント セクションの下部をご覧ください)

于 2015-12-01T15:10:06.000 に答える