RESTEasy - add a resource class dynamically

后端 未结 3 1342
醉梦人生
醉梦人生 2021-01-24 10:59

With RESTEasy I\'ve implemented a subclass of Application to provide a list of singleton resources. Is there a way to add another singleton dynamically later on? I\'ve not found

3条回答
  •  遥遥无期
    2021-01-24 11:21

    I use Reateasy with Undertow in embedded environment, where I manually instantiate ResteasyDeployment, and register Resource class is really easy, see code snippet blow:

        UndertowJaxrsServer undertowJaxrsServer = new UndertowJaxrsServer();
        ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
    
        undertowJaxrsServer.start();
        resteasyDeployment.start();
    
        final DeploymentInfo undertowDeployment =
            undertowJaxrsServer
                .undertowDeployment(resteasyDeployment)
                .setContextPath("/abc")
                .setDeploymentName("TEST")
                .setClassLoader(Thread.currentThread().getContextClassLoader());
    
        undertowJaxrsServer.deploy(undertowDeployment);
    
        resteasyDeployment.getRegistry().addSingletonResource(new ResourceApiImpl());
    

提交回复
热议问题