使用球衣的例外

时间:2019-07-15 06:28:03

标签: java rest jersey

我想使用Jersey启动REST Web服务。多个教程指出这是一种方法:

ResourceConfig resourceConfig = new PackagesResourceConfig(TestSystem.class.getPackageName());
HttpServer server = HttpServerFactory.create("http://localhost:8080/rest", resourceConfig);
server.start();

声明为

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.19.4</version>
</dependency>

但是我得到了

java.lang.IllegalArgumentException
    at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
    at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
    at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:424)
    at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138)
    at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
    at com.sun.jersey.core.util.Closing.f(Closing.java:71)
    at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
    at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:226)
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:142)

(即使我不使用resourceConfig。)

自然地,我的第一个直觉是Jersey一定有问题,所以我尝试了 1.18.1

java.lang.ArrayIndexOutOfBoundsException: Index 52264 out of bounds for length 287
    at jersey.repackaged.org.objectweb.asm.ClassReader.readClass(ClassReader.java:1976)
    at jersey.repackaged.org.objectweb.asm.ClassReader.accept(ClassReader.java:464)
    at jersey.repackaged.org.objectweb.asm.ClassReader.accept(ClassReader.java:420)
    at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138)
    at com.sun.jersey.core.spi.scanning.JarFileScanner.scan(JarFileScanner.java:97)
    at com.sun.jersey.core.spi.scanning.JarFileScanner$1.f(JarFileScanner.java:74)
    at com.sun.jersey.core.util.Closing.f(Closing.java:71)

对于高于1.19的所有内容,我都会遇到第一个例外,低于其的所有内容都是第二个例外。所以也许我的网络服务出了点问题:

@ApplicationPath(TestSystem.URL)
public class TestSystem extends Application {

    public static final String URL = "/testsystem/";
}

@Path(HelloWorldEndpoint.URL)
public class HelloWorldEndpoint {

    public static final String URL = "hello";

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/")
    public String greet() {
        return "Hello World!";
    }
}

如何使用Jersey启动我的REST Web服务?

0 个答案:

没有答案