为什么我不能创建webserviceprovider基类?

时间:2019-07-24 14:33:02

标签: java eclipse rest jax-ws

如果我按如下方式创建一个类,则效果很好:

@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...

但是,如果我使该类扩展BaseRestAPI并尝试将所有注释,带注释的对象和方法移动到基类中,则会在Eclipse中出现错误:

@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());           
    }

这不会给我任何编译错误,但是会在运行时出现:

  

线程“ main”中的异常java.lang.IllegalArgumentException:类SpecificRestAPI没有@WebService和@WebServiceProvider注释

如果我只是将注释移至SpecificRestAPI类,那么它会抱怨我没有实现Provider-但我只是在基类中。

1 个答案:

答案 0 :(得分:0)

子类不会从父类继承注释-因此需要在子类中重复注释。