[英]How to expose multiple interface from a single singleton in RestEasy
Let's say we have the following service interfaces: 假设我们有以下服务接口:
@Path("servicea")
public interface ServiceA {
@GET void aMethod();
}
@Path("serviceb")
public interface ServiceB {
@GET void anotherMethod();
}
Now, using RestEasy these can easily be exposed as a Rest service using any of the configuration supported. 现在,使用RestEasy,可以使用任何受支持的配置轻松地将这些作为Rest服务公开。 In this case, we have an implementation for
ServiceA
and one for ServiceB
, which we export via org.jboss.resteasy.spi.Registry
, like so: 在这种情况下,我们有一个
ServiceA
实现和一个ServiceB
,我们通过org.jboss.resteasy.spi.Registry
导出,如下所示:
Registry registry = (Registry) servletContext.getAttribute("org.jboss.resteasy.spi.Registry");
registry.addSingletonResource(serviceAimpl);
registry.addSingletonResource(serviceBimpl);
This works fine. 这很好。 But now, let's say it makes sense to group the two implementation together, under a single class:
但是现在,让我们说将两个实现归为一个类是有意义的:
public class ServiceImpl implements ServiceA, ServiceB {
...
}
Registry registry = (Registry) servletContext.getAttribute("org.jboss.resteasy.spi.Registry");
registry.addSingletonResource(serviceImpl);
I would expect that when I register an object of this class to RestEasy to expose both paths, but it seems like it expose only one of the two. 我希望当我向RestEasy注册此类的对象以公开这两个路径时,但似乎只公开这两个路径之一。 Is there a way to achieve this?
有没有办法做到这一点? Or is this a bug in RestEasy?
还是这是RestEasy中的错误?
Logically the Impl class cannot have two @Path
annotation at class level and within a class there can be only one GET
method without the @Path
. 从逻辑上讲,Impl类不能在类级别具有两个
@Path
注释,并且在一个类内,只有一个GET
方法而没有@Path
。 So it is not possible. 因此这是不可能的。 You can annotate your interface
methods
with @Path
and that would be honoured. 您可以使用
@Path
注释您的接口methods
,这一@Path
被兑现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.