以下java代码的正确pom依赖是什么?

时间:2015-07-22 10:39:36

标签: java dependencies pom.xml server-sent-events tomcat8

错误

  

org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service()   for servlet [org.javaee7.jaxrs.serversentevent.MyApplication] in   路径[/broadcast-0.0.1-SNAPSHOT]的上下文抛出异常[Servlet   执行引发异常]有根本原因   java.lang.AbstractMethodError:   javax.ws.rs.core.UriBuilder.uri(Ljava /郎/字符串;)Ljavax / WS / RS /型芯/ UriBuilder;     在javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)at   com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:725)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)     在   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:652)     在   org.apache.coyote.http11.Http11NioProtocol $ Http11ConnectionHandler.process(Http11NioProtocol.java:222)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1575)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1533)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)     在java.lang.Thread.run(未知来源)

的pom.xml

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-sse</artifactId>
            <version>2.0-m13-2</version>
        </dependency>
        <dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.19</version>
</dependency>
  </dependencies>

我的tomcat版本是8.0。

Java代码:

import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.media.sse.SseFeature;
import org.glassfish.jersey.server.ResourceConfig;

@ApplicationPath("webresources")
public class MyDemo extends ResourceConfig {
    public MyDemo() {
        super(MyResource.class, SseFeature.class);
    }
}

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.media.sse.EventOutput;
import org.glassfish.jersey.media.sse.OutboundEvent;
import org.glassfish.jersey.media.sse.SseBroadcaster;
import org.glassfish.jersey.media.sse.SseFeature;


@Path("test")
public class MyResource {

    private static final SseBroadcaster BROADCASTER = new SseBroadcaster();

    @GET
    @Path("hello")
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput itemEvents() {
        final EventOutput eventOutput = new EventOutput();
        BROADCASTER.add(eventOutput);
        return eventOutput;
    }

    @POST
    public void addItem(e) {

        BROADCASTER.broadcast(new OutboundEvent.Builder().data(String.class, "hello").build());

    }
}

1 个答案:

答案 0 :(得分:0)

您的错误日志清楚地说明了您的问题。你的依赖没有问题。您试图调用抽象方法uri。检查此documentation。您必须找到一个实现此uri方法的类。