1

Undertow を単純なサーブレット コンテナーとして実行しています。Resteasy サーブレットをデプロイしました。

    ResteasyDeployment restEasyDeployment = new ResteasyDeployment();

    Reflections reflections = new Reflections("");
    Set<Class<?>> resourceClassSet = reflections.getTypesAnnotatedWith(Path.class);
    restEasyDeployment.getActualResourceClasses().addAll(resourceClassSet);

    ServletInfo servletInfo = Servlets.servlet("RestEasyServlet", HttpServlet30Dispatcher.class);
    servletInfo.setAsyncSupported(true)
            .setLoadOnStartup(1)
            .addMapping("/*");

    DeploymentInfo deploymentInfo = new DeploymentInfo();
    deploymentInfo.setContextPath(path)
                    .addServletContextAttribute(ResteasyDeployment.class.getName(), restEasyDeployment)
                    .addServlet(servletInfo)
                    .setDeploymentName("api")
                    .setClassLoader(ClassLoader.getSystemClassLoader());

    DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(deploymentInfo);
    deploymentManager.deploy();

このコードは、このチュートリアルこのコードに基づいています。

Resteasy 内にデプロイされたリソースに構築パラメータを提供する方法は?

静的フィールドを使用するチュートリアルを見ましたが、簡単にテストできるように依存関係の反転を維持したいと考えています。サーブレットの世界では、すべてをコンテキストに入れるのが正しい方法です。

4

0 に答える 0