I'm new to both Resteasy and Guice, but I'm having problems getting the simple tutorial to work. Here are my relevant files. I have reproduced the error below, but I have not seen anyone with the same problem as me. I have gotten Resteasy to work without Guice, after adding the provided tag in pom for resteasy-jaxrs, but that seems to be not there with resteasy-guice. I hope someone can please point me in the right direction.
Thanks
MyModule.java
package foo.guice;
import com.google.inject.Module;
import com.google.inject.Binder;
import foo.rest.Controller;
public class MyModule implements Module {
@Override
public void configure(final Binder binder) {
binder.bind(Controller.class);
}
}
Controller.java
package foo.rest;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import com.google.inject.Inject;
@Path("hello")
public class Controller
{
@GET
@Path("{name}")
public String hello(@PathParam("name") final String name) {
return "Hello " + name;
}
}
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<packaging>war</packaging>
<version>1.0.war</version>
<name>FooBar</name>
<dependencies>
<!-- Jackson JSON library -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0-beta</version>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
<!-- RESTEasy libraries -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-guice</artifactId>
<version>3.0.4.Final</version>
</dependency>
<!-- For testing purposes -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.6.v20130930</version>
</plugin>
</plugins>
</build>
</project>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>FooBar</display-name>
<context-param>
<param-name>resteasy.guice.modules</param-name>
<param-value>foo.guice.MyModule</param-value>
</context-param>
<!-- Setting up RESTEasy as in http://docs.jboss.org/resteasy/docs/3.0.4.Final/userguide/html/Guice1.html -->
<listener>
<listener-class>
org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
And here is the output from server.log
11:14:14,410 INFO [org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener] (MSC service thread 1-2) found module: foo.guice.MyModule
11:14:14,610 INFO [org.jboss.resteasy.plugins.guice.ModuleProcessor] (MSC service thread 1-2) registering factory for foo.rest.Controller
11:14:14,612 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/bar-1.0]] (MSC service thread 1-2) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener: java.lang.AbstractMethodError: org.jboss.resteasy.plugins.guice.GuiceResourceFactory.registered(Lorg/jboss/resteasy/spi/InjectorFactory;)V
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:121) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:107) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:84) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.guice.ModuleProcessor.processInjector(ModuleProcessor.java:41) [resteasy-guice-3.0.4.Final.jar:]
at org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener.contextInitialized(GuiceResteasyBootstrapServletContextListener.java:51) [resteasy-guice-3.0.4.Final.jar:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
11:14:14,679 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Error listenerStart
11:14:14,680 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Context [/bar-1.0] startup failed due to previous errors
11:14:14,695 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/bar-1.0]] (MSC service thread 1-2) Exception sending context destroyed event to listener instance of class org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener: java.lang.NullPointerException
at org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener.triggerAnnotatedMethods(GuiceResteasyBootstrapServletContextListener.java:137) [resteasy-guice-3.0.4.Final.jar:]
at org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener.contextDestroyed(GuiceResteasyBootstrapServletContextListener.java:132) [resteasy-guice-3.0.4.Final.jar:]
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3489) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3999) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3917) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
11:14:14,718 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.web.deployment.default-host."/bar-1.0": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/bar-1.0": JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
11:14:14,932 INFO [org.jboss.as.server] (management-handler-thread - 2) JBAS015870: Deploy of deployment "bar-1.0.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host.\"/bar-1.0\"" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host.\"/bar-1.0\": JBAS018040: Failed to start context"}}
11:14:14,987 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment bar-1.0.war in 54ms
11:14:14,991 INFO [org.jboss.as.controller] (management-handler-thread - 2) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.web.deployment.default-host."/bar-1.0": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/bar-1.0": JBAS018040: Failed to start context