2016-10-14 2 views
2

jerseyとjavaで構築された独自のREST APIを使用しています。今日は、それに取り組んでいる友人が自分の変更をプッシュした後も、それは動作を停止しました。彼は依存関係の側で何も変更しなかったが、彼は主APIクラスが作成するコントローラを追加した。我々は、彼が依存関係をjsoup追加した後、それが開始信じ独自のREST APIを作成するとサーブレット実行例外がスローされる

exception 

javax.servlet.ServletException: Servlet execution threw an exception 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
root cause 

java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder; 
    javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119) 
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.ja 

:私は、リソースに到達しようとする時はいつでも今Tomcatサーバーでエラーが発生します。

EDIT: 私の依存関係とweb.xmlを編集しましたが、今は404が見つかりません。

これは私の依存関係が

<dependencies> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>2.23.2</version> 
     </dependency>  
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet-core</artifactId> 
      <version>2.23.2</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.codehaus.jettison</groupId> 
      <artifactId>jettison</artifactId> 
      <version>1.3.8</version> 
     </dependency> 
     <dependency> 
     <groupId>org.jsoup</groupId> 
      <artifactId>jsoup</artifactId> 
      <version>1.9.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.twitter4j</groupId> 
      <artifactId>twitter4j-core</artifactId> 
      <version>[4.0,)</version> 
     </dependency> 
     <dependency> 
      <groupId>org.facebook4j</groupId> 
      <artifactId>facebook4j-core</artifactId> 
      <version>[2.4,)</version> 
     </dependency> 
    </dependencies> 

私のpom.xmlを形成する。これは私のweb.xmlです:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 
    <display-name>api</display-name> 
    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 



    <servlet> 
     <servlet-name>Jersey Web Application</servlet-name> 
     <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Jersey Web Application</servlet-name> 
     <url-pattern>/api/*</url-pattern> 
    </servlet-mapping> 

</web-app> 

編集 私が到達しようとした場合:http://localhost:8080/api-mashup-api/api/v1/foobar

@Path("/v1") 
public class API { 
private Controller controller; 

public API(){ 
    controller = new Controller(); 
} 


/** 
* Prints to the screen if we are in /v1/foobar 
* 
* @return 
*/ 
@GET 
@Path("/foobar") 
@Produces(MediaType.TEXT_HTML) 
public String print2() { 
    return "Please specify what resource you need."; 
} 

私はただ404を得る。

+0

シェアコード –

+0

シェアコードと詳細情報 – Nivesh

+0

「今すぐ私はリソースにアクセスしようとします。」:あなたのリソースはどのように構成されていますか?あなたが到達しようとしているURIは何ですか? 「コントローラー」はどういう意味ですか? – ujulu

答えて

0

1)アプリケーションで抽象メソッドを呼び出そうとしたときにスローされるAbstractMethodError例外があります。
uriは、UriBuilderの抽象メソッドなので、これを実装する必要があります。

JAX-RS 2.0には、JAX-RS 2.0を実装し、uriメソッドへの実装が含まれています。あなたのスタックトレースを見ることによって

2)は、それは明らかにあなたが1 & 2を使用して、両方のジャージーのバージョンされていることを述べ、それは不可能です、だから、クラスローダは間違っURIBuilderクラスを拾っています。

スタックトレース:グループcom.sun.jersey

com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669) 

ザジャージーの依​​存関係は、すべてのジャージーバージョン1ジャージーバージョン2グループorg.glassfish.jerseyを使用しています。おそらく、あなたの問題が間違っuribuilderは、撮像された

https://jersey.java.net/documentation/latest/modules-and-dependencies.html#server-jdk

ジャージーコンテナサーブレット =>ジャージーコアサーブレット3.xのように発生することがあり、誤ったジャージーコンテナサーブレットによって引き起こさ

+0

私の編集でわかるように、私はそれを修正しました。今は404になっています。以前はジャージー1.xを使用しましたが、昨日は2.23.2に変更しても問題ありませんでした。 – stackerlow

+0

はい、私は見ることができますが、あなたの変更はまだ反映されていません。あなたのプロジェクトからジャージー1ジャーにいくつかのリンケージがあります。いくつかのクリーンアップを行う必要があります、もしmavenがそれをダウンロードした場所から存在するなら、ジャージー1ジャーを削除してください。それ以外の場合は、新しいプロジェクトを作成し、コードベースをコピーしてコピーします。 –

1

実装

ジャージーコンテナーサーブレットコア =>ジャージーコアサーブレット2。X実装

変更:

<dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet</artifactId> 
      <version>2.23.2</version> 
      <scope>provided</scope> 
     </dependency> 

<dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet-core</artifactId> 
      <version>2.23.2</version> 
      <scope>provided</scope> 
     </dependency> 

また(非JAX-RSは統合)のコンテナあなたはGlassfishのと、他のサーブレットベースを提供する必要がある依存関係を調べるためにhttps://jersey.java.net/documentation/latest/modules-and-dependencies.html#dependenciesを参照してください。

関連する問題