2012-03-19 19 views
0

Guiceを初めて使用しています。 私は、RESTful WebサービスとGuiceのDI用サーバーアプリケーションを作成したいと思います。私はチュートリアルhereに従いました。私はTomcat6を使っています。しかし、私はそれを実行するために:(com.sun.jersey.guice.spi.container.servlet.GuiceContainerで適切なコンストラクタが見つかりませんでした。

を得ることができない私はいつもは、アプリケーションの起動時にcom.sun.jersey.guice.spi.container.servlet.GuiceContainerで、適切なコンストラクタが見つかりませんでした取得します。

コンテキスト初期化イベントをクラスde.server.MyGuiceServletConfigのリスナーインスタンスに送信する例外 com.google.inject.CreationException:Guice作成エラー: 1)com.sun.jersey.guice.spi.containerで適切なコンストラクタを見つけることができませんでした。サーブレット.GuiceContainer。クラスには、@ Injectで注釈されたコンストラクタが1つだけ(または1つだけ)存在する必要があります。 com.sun.jersey.guice.JerseyServletModule.webAppでcom.sun.jersey.guice.spi.container.servlet.GuiceContainer.class(GuiceContainer.java:108) で(JerseyServletModule.java:90)

GuiceContainerクラスには、Injectorが必要な@Inject文を持つコンストラクタがあります。

@Inject 
public GuiceContainer(Injector injector) { 
    this.injector = injector; 
} 

私のweb.xmlが次のようになります。

public class MyGuiceServletConfig extends GuiceServletContextListener { 

public MyGuiceServletConfig() { 

} 

public class MyJerseyServletModule extends JerseyServletModule { 
    @Override 
    protected void configureServlets() { 
     // Must configure at least one JAX-RS resource or the 
     // server will fail to start. 
     bind(ITest.class).to(Test2.class); 
     bind(TestRestService.class); 

     serve("/*").with(GuiceContainer.class); 
    } 
} 

@Override 
protected Injector getInjector() { 
    return Guice.createInjector(new MyJerseyServletModule()); 
}} 

そして最後にではなく、少なくとも残りのサービス:

私のconfigクラスは次のようになります

<web-app id="WebApp_ID" version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
<display-name>Restful Web Application</display-name> 
<filter> 
    <filter-name>guiceFilter</filter-name> 
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>guiceFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<listener> 
    <listener-class>de.server.MyGuiceServletConfig</listener-class> 
</listener> 

<context-param> 
    <param-name>resteasy.scan</param-name> 
    <param-value>true</param-value> 
</context-param> 

<context-param> 
    <param-name>resteasy.servlet.mapping.prefix</param-name> 
    <param-value>/rest</param-value> 
</context-param> 

<listener> 
    <listener-class> 
     org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap 
    </listener-class> 
</listener> 

<servlet> 
    <servlet-name>resteasy-servlet</servlet-name> 
    <servlet-class> 
     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher 
    </servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>resteasy-servlet</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

@Path("/test") 
public class TestRestService { 

private ITest test; 

@Inject 
public TestRestService(ITest t){ 
    this.test = t; 
} 

@GET 
@Path("/getMe") 
public String getMe() { 
    return test.getName(); 
} 


@GET 
@Path("/getAll") 
public Response getAll() { 
    return Response.status(200).entity("sadsads").build(); 
}} 

私は何が欠けているのか分かりません。私が間違ったことを教えてくれることを願っています...

さらなる情報が必要な場合は、コメントを残しておいてください。事前に

Thxを、[OK]を TJ

答えて

0

は、私が問題を発見しました。

は、それは少し奇妙に聞こえるが、問題がある(私はそれが問題を引き起こし、ビルドプロセスであることが示唆されたことがない原因私は、私の質問でそれを言及していなかった)次:私は定義されて

私のpomの最終的な名前:

<build> 
<finalName>mytest</finalName> 

これはまさに問題です。この行を削除すると、すべてが完璧に機能します...

戦争を行う際に最終的な名前を入力するのがなぜ難しいのですか?

+1

私は最近同じ問題を抱えていました。私は解決策がfinalNameを変更した後にmvnをきれいにしたと実際考えていたと思います。私は私の構成を見て約3時間後にmvnのクリーンなパッケージでこの問題を解決しました。私はmvn warを実行していました.pomに依存関係を追加した後、依存関係をコピーする戦争です。これでサーバが正常に起動しましたが、「mvn cleanパッケージ」でしか解決できない問題がいくつかあったと思います。 –

関連する問題