Resteasy003130:class is not a root resource problem reason __dubbox

Source: Internet
Author: User
Problem Description

Today, when using Dubbox, when you start the service, an error is reported, causing the application to fail to start, and the error message is:
Initialization of Bean failed; Nested exception is java.lang.RuntimeException:RESTEASY003130:Class isn't a root resource. It, or one of its interfaces must is annotated with @Path

Dubbox is a restful extension based on Dubbo, with Jax-rs extensions, so that restful calls can be supported, and the default invocation should be as follows:

Interface:

@Path ("interface/dosomething")
@Consumes (Mediatype.application_json)
@Produces (mediatype.application_ JSON) Public
interface Testservice {

    @POST
    @Path ("Run")
    Boolean test (Testdto dto);
}

Interface Implements:

@Service public
class Testserviceimpl implements Testservice {

    @Override public
    boolean test (Testdto dto) {
        //dosomething ...
    }}

Since Dubbox is implemented based on Dubbo, when we have some methods that do not want to provide restful interface, we simply provide the Dubbo call.

So I took it for granted:

Public interface Testservice {

    boolean test (Testdto dto);
}

I removed the annotations from the Jax-rs in the interface, so that I could simply provide the Dubbo invocation without providing a restful call, and then when I started the project, I reported the error above ... problem Reason

Found a lot of information to find out why, because Dubbox support jax-rs, so add the appropriate jar file, which has resteasy, in which a class Resourcemethodregistry.java The Addresourcefactory () method in, found the cause of the problem:

/**
    * Resourcefactory.getscannableclass () defines what class should is scanned
    * for jax-rs annotations.    The class and any implemented interfaces are scanned for annotations.
    * *
    @param ref
    * @param base base URI path for all provided by the factory, in addition to RootPath
    *
   /public void addresourcefactory (resourcefactory ref, String Base)
   {
      class<?> clazz = Ref.getscannableclass ();
      Class restful = Getrestful.getrootresourceclass (clazz);
      if (restful = = null)
      {
         String msg = Messages.MESSAGES.classIsNotRootResource (Clazz.getname ());
         For (Class intf:clazz.getInterfaces ())
         {
            msg = "" + intf.getname ();
         }
         throw new RuntimeException (msg);
      Addresourcefactory (ref, Base, restful);
   

You can see that Resourcefactory.getscannableclass () defines which class files to scan and go to the specific implementation:

public class Dubboresourcefactory implements Resourcefactory {

    private Object resourceinstance;
    Private Class Scannableclass;

    Public Dubboresourcefactory (Object resourceinstance, Class scannableclass) {
        this.resourceinstance = resourceinstance;
        This.scannableclass = Scannableclass;
    }

    Public class<?> Getscannableclass () {return
        scannableclass;
    }
}    

Here only a part of the source code, from this can be seen scannableclass by the Dubbo annotation class, so you can understand the cause of the error, JAX-RS will scan the Dubbo annotation class implementation of the interface, The exception was thrown because the interface has no annotation @path. Summary

After using Dubbox, the class that provides the Dubbo service must annotate the @path, and even if no restful call is provided in the class, the exception of "Class is not a root resource" will be reported. So there's really no method in our class that needs to provide a restful call. No annotations can be made on the method, and this can only be done in a Dubbo manner

 @Path ("interface/dosomething") @Consumes (Mediatype.application_json) @Produces ( Mediatype.application_json) public interface Testservice {boolean test (Testdto dto);} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.