Jersey的问题

xiaoyang_job 2011-03-22 05:19:16
web.xml配置如下:

<!-- Spring Configuration -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Jersey Spring Web Application</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Jersey Spring Web Application</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>


如下发布没有问题,当发布类实现某个接口就不行了,访问页面直接报404错误.

@Component
@Path("/test")
public class Hello {
@Path("/getMsg")
@GET
@Produces("text/plain")
public String getClichedMessage() {
return "Hello World";
}
}


错误的代码:

@Component
@Path("/test")
public class Hello implements IHello {...}


请问大家这是什么原因?
...全文
87 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
404 的话是不是你把资源路径弄错了?

http://localhost:8080/project/services/test/getMsg

是这样不?
  • 打赏
  • 举报
回复
我的完全没有问题,呵呵:


import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.springframework.stereotype.Component;

@Component
@Path("/test")
public class HelloImpl implements Hello {

@Path("/getMsg")
@GET
@Produces("text/plain")
public String getClichedMessage() {
return "Hello World";
}
}
  • 打赏
  • 举报
回复
还有这么妖的事情?

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧