为什么我不能创建一个 webserviceprovider base class?

Why can't I make a webserviceprovider base class?

我正在尝试为我的各种 REST API 创建一个基础class。

如果我按如下方式创建一个 class,没有基础 class,那么它工作正常(我的重构起点也是如此):

@WebServiceProvider
@ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)
@BindingType(value = HTTPBinding.HTTP_BINDING)
public class SpecificRestAPI implements Provider<Source>
{
    // arg 0: url including port, e.g. "http://localhost:9902/specificrestapi"
    public static void main(String[] args)
    {
        String url = args[0];
        // Start
        Endpoint.publish(url, new SpecificRestAPI());       
    }

    @Resource
    private WebServiceContext wsContext;


    @Override
       public Source invoke(Source request)
       {
          if (wsContext == null)
             throw new RuntimeException("dependency injection failed on wsContext");
          MessageContext msgContext = wsContext.getMessageContext();
          switch (((String) msgContext.get(MessageContext.HTTP_REQUEST_METHOD)).toUpperCase().trim())
          {
             case "DELETE": 
                 return processDelete(msgContext);
'etc...

但是,如果我使 class 扩展 BaseRestAPI 并尝试将所有注释和注释对象和方法移动到基础 class 中,我会得到一个错误:

@WebServiceProvider
@ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)
@BindingType(value = HTTPBinding.HTTP_BINDING)
public abstract class BaseRestAPI  implements Provider<Source>
{
    @Resource
    private WebServiceContext wsContext;


    @Override
       public Source invoke(Source request)
       {
'etc...


public class SpecificRestAPI extends BaseRestAPI
{
    // arg 0: url including port, e.g. "http://localhost:9902/specificrestapi"
    public static void main(String[] args)
    {
        String url = args[0];
        // Start
        Endpoint.publish(url, new SpecificRestAPI());           
    }

这没有给我编译错误,但在 运行 时间:

Exception in thread "main" java.lang.IllegalArgumentException: class SpecificRestAPI has neither @WebService nor @WebServiceProvider annotation

基于这个错误,然后我尝试将该注释移动到 SpecificRestAPI class,而其余的 Base class 则如上;但后来我得到一个 Eclipse 编译器错误,我没有实现 Provider - 但我只是在基础 class...

这是以前有人做过的事吗?如果是的话怎么办?

注释不是由子 classes 从父 classes 继承的 - 因此注释需要在子 class.

中重复