运行 灰熊队球衣
Running Jersey with Grizzly
我正在尝试将 Jersey with Grizzly 用作自托管
基本上我的主要是:
org.glassfish.jersey.server.ResourceConfig rc = new ResourceConfig();
rc.registerClasses(DummyController.class);
webServer = GrizzlyHttpServerFactory.createHttpServer(uri, rc, false);
System.out.println("Server Created");
try {
webServer.start();
System.out.println("Server Started");
} catch (IOException e) {
}
我创建了一个小控制器:
@Path("/")
public class DummyController {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "Got it!";
}
}
但是,当我 运行 它时,我得到一个异常:
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:309)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:289)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:331)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:141)
at RestServer.Server.main(Server.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
当我没有添加资源时,grizzly 服务器运行正常,但我无法访问任何控制器
我已经使用Maven下载了所有的依赖
这是 pom 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestRestServer</groupId>
<artifactId>TestRestServer</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-framework</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<version>2.15</version>
</dependency>
</dependencies>
解决方案是在 pom.xml
中将依赖关系从 com.sun.jersey
更改为 org.glassfish.jersey
。第一个包含 JAX-RS 1.x API 的实现(Java EE 6 的一部分),后者包含 JAX-RS 2.0 API 实现(API 的一部分=16=] EE 7).
我正在尝试将 Jersey with Grizzly 用作自托管
基本上我的主要是:
org.glassfish.jersey.server.ResourceConfig rc = new ResourceConfig();
rc.registerClasses(DummyController.class);
webServer = GrizzlyHttpServerFactory.createHttpServer(uri, rc, false);
System.out.println("Server Created");
try {
webServer.start();
System.out.println("Server Started");
} catch (IOException e) {
}
我创建了一个小控制器:
@Path("/")
public class DummyController {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "Got it!";
}
}
但是,当我 运行 它时,我得到一个异常:
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:309)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:289)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:331)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:141)
at RestServer.Server.main(Server.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
当我没有添加资源时,grizzly 服务器运行正常,但我无法访问任何控制器
我已经使用Maven下载了所有的依赖
这是 pom 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestRestServer</groupId>
<artifactId>TestRestServer</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-framework</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<version>2.15</version>
</dependency>
</dependencies>
解决方案是在 pom.xml
中将依赖关系从 com.sun.jersey
更改为 org.glassfish.jersey
。第一个包含 JAX-RS 1.x API 的实现(Java EE 6 的一部分),后者包含 JAX-RS 2.0 API 实现(API 的一部分=16=] EE 7).