Jboss RESTEasy-在接口中标记@Path时资源类注册失败
我正在JBoss4.3.0.GA上使用RESTEasy 2.0.1.GA。 我的资源类实现的接口如下所示:Jboss RESTEasy-在接口中标记@Path时资源类注册失败,jboss,jax-rs,resteasy,Jboss,Jax Rs,Resteasy,我正在JBoss4.3.0.GA上使用RESTEasy 2.0.1.GA。 我的资源类实现的接口如下所示: @Path("/") public interface CwindRestfulService { @GET @Path("accounts/{email}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Account getAccountInf
@Path("/")
public interface CwindRestfulService {
@GET
@Path("accounts/{email}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Account getAccountInfo(@PathParam("email") String email) throws Exception;
}
当我在web.xml中设置resteasy.scan=true时,效果很好。但在spring上下文中应该是错误的。现在我的web.xml是:
<web-app>
<display-name>Archetype RestEasy Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>com.cwind.rest.CwindRestfulServiceImpl</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</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>
这表明我错过了@Path,而实际上我没有。但当我将注释放入资源类时,它确实起作用。我在谷歌上搜索并找到了一个解决方案。它需要添加@ApplicationPath注释。现在我的接口在第三方库中,所以我不能修改它。有人有什么建议吗?提前感谢。您似乎尚未注册特定于Resteasy的
SpringContextLoaderListener
。这是Spring向Resteasy注册扫描的资源类所必需的
下面是web.xml配置示例(它使用注释配置,但也可用于xml配置):
非常感谢格雷格!现在它起作用了。但还有一件事,@Path必须添加到资源类中,当注释仅在接口中时,它将不起作用。
2014-02-20 18:10:23,303 ERROR [org.apache.catalina.core.ContainerBase] Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
java.lang.RuntimeException: Class is not a root resource. It, or one of its interfaces must be annotated with @Path: com.cwind.rest.CwindRestfulServiceImpl implements: com.cwind.rest.CwindRestfulService
<!-- Spring Configuration -->
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.myapp.SpringConfig</param-value>
</context-param>
<!-- RESTEasy Configuration -->
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/</param-value>
</context-param>
<!-- RESTEasy <-> Spring Connector (Needed so that RESTEasy has access to Spring managed beans!) -->
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<!-- RESTEasy HTTP Request Processor Servlet -->
<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>/*</url-pattern>
</servlet-mapping>
@Named
@Path("/")
public class MyResource implements CwindRestfulService
{
//Stuff Goes Here...
}