1

小さな REST アプリケーションをテストするために、Jersey の InMemoryTestContainer を使用しています。今、データソース オブジェクトを作成し、以下のようstart()InMemoryTestContainerのコンテキストにバインドしています。

    @Override
    public void start() {
        if (!webApp.isInitiated()) {
            logger.info("Starting low level InMemory test container");

            try {
                //Create datasource and bind it  
                initDataSource();
            } catch (ClassNotFoundException | NamingException e) {
                e.printStackTrace();
            }

            webApp.initiate(resourceConfig, new GuiceComponentProviderFactory(resourceConfig, injector) {
                @Override
                public Map<Scope, ComponentScope> createScopeMap() {
                    Map<Scope, ComponentScope> m = super.createScopeMap();

                    m.put(ServletScopes.REQUEST, ComponentScope.PerRequest);
                    return m;
                }
            });
        }
    }

tomcat では、context.xml に情報を入力してデータソースを作成します。InMemoryTestContainer でそのような標準的な方法はありますか?

4

0 に答える 0