RESTEasy - add a resource class dynamically

后端 未结 3 1341
醉梦人生
醉梦人生 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:28

    I have not tried this myself, but I found a blog post where this is described: http://sarbarian.wordpress.com/2010/03/07/resteasy-and-osgi-perfect-match/

    During deployment, RESTEasy puts it's registry in the servlet context. The idea suggstested in the blog, is that you fetch the registry from the servlet context, and then add your resource class.

    Something like this:

    import org.jboss.resteasy.spi.Registry;
    
    Object resource = new MyService();
    Registry registry = (Registry) context.getAttribute(Registry.class.getName());
    registry.addSingletonResource(resource);
    

提交回复
热议问题