RESTEasy - 动态添加资源类 [英] RESTEasy - add a resource class dynamically

查看:55
本文介绍了RESTEasy - 动态添加资源类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 RESTEasy,我实现了 Application 的一个子类来提供单例资源列表.有没有办法稍后动态添加另一个单例?我还没有从 API 文档中找到这样做的方法.

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 a way to do it from the API docs.

推荐答案

我自己没有尝试过,但我找到了一篇博客文章,其中描述了这一点:http://sarbarian.wordpress.com/2010/03/07/resteasy-and-osgi-perfect-match/

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/

在部署期间,RESTEasy 将其注册表放在 servlet 上下文中.博客中建议的想法是,您从 servlet 上下文中获取注册表,然后添加您的资源类.

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.

像这样:

import org.jboss.resteasy.spi.Registry;

Object resource = new MyService();
Registry registry = (Registry) context.getAttribute(Registry.class.getName());
registry.addSingletonResource(resource);

这篇关于RESTEasy - 动态添加资源类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆