spring+cxf+jdbc

xiechunmei13 2009-08-23 09:08:14
做接口的时候。一直调用不到接口。执行返回为500
这是控制台给的警告。
其他就没错误信息了。
2009-8-23 21:03:23 org.apache.cxf.jaxrs.provider.AbstractJAXBProvider handleJAXBException
警告: JAXBException occurred : 1 counts of IllegalAnnotationExceptions
2009-8-23 21:03:23 org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
警告: WebApplicationException has been caught : 1 counts of IllegalAnnotationExceptions

这是测试类代码:
	
@Test
public void testSaveOrUpdate(){
String url = "http://localhost:8081/services/userservices/adduser";
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(url);
postMethod.setRequestHeader("Content-type","application/xml");
postMethod.setRequestHeader("user", "vis");
postMethod.setRequestHeader("pass", "vis@amoy");
postMethod.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("testAddUsers.xml")));
try{
int status = httpClient.executeMethod(postMethod);
if(status == HttpStatus.SC_OK){
System.out.println(new String(postMethod.getResponseBody(), "utf-8"));
}
}catch (HttpException e) {
throw new RuntimeException("",e);
} catch (IOException e) {
throw new RuntimeException("",e);
}finally{
postMethod.releaseConnection();
}
}


这是service代码:
@Path("/userservices/")
@Produces("application/xml")
public class UserService {
@Context
private org.apache.cxf.jaxrs.ext.MessageContext messageContext;

@POST
@Path("/adduser")
@Consumes("application/xml")
public Response saveOrUpdate(VisUsers users) {
if(Authentication.validate(messageContext)){
int result=userDao.saveOrUpdate(users);
if(result>0){
return Response.status(200).entity("Save OK!").build();
}else{
return Response.status(401).entity("insert user error!").build();
}
}else{
return Response.status(401).build();
}
}

配置文件:
<bean id="userservices" class="com.sns.bestv.service.impl.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
<jaxrs:server id="mmberService_wa" address="/">
<jaxrs:serviceBeans>
<ref bean="mmberService" />
<ref bean="userservices" />
</jaxrs:serviceBeans>
</jaxrs:server>


我测试为撒到不了接口呢?
应该说是到接口了。因为返回是500不是404应该证明是有到接口这边了。
可是那个警告什么意思?

...全文
432 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tony_1201 2011-10-22
  • 打赏
  • 举报
回复
我的已经解决,返回 500的问题,估计你缺少传过去的参数,仔细看看访问的网页。
tony_1201 2011-10-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xiechunmei13 的回复:]
以上问题已经解决!

错误的意思是有一个无效的注解
我的实体类的注解写错了。我的是:@XmlRootElement

应该是
@XmlRootElement(name = "VisUsers")

第一开始只以为是这个的错。
无效注解应该是这里的错。
但是这个解决后紧接着就给我说date参数的错误

是由于我的实体类中有date类型,为sql date
将sql date……
[/Quote]

请教具体代码,我现在也是返回 500 ?
xiechunmei13 2009-08-24
  • 打赏
  • 举报
回复
我被你吓到了。以为有人回答我了。
汗~~~

打印控制太错误信息为:
JAXBException occurred : 1 counts of IllegalAnnotationExceptions
经过调试我发现service方法已经全部执行,数据库取值已经得到。
但是返回后
int status = httpClient.executeMethod(postMethod);
也就是这句返回500
期待有研究cxf的朋友~~~
xiechunmei13 2009-08-24
  • 打赏
  • 举报
回复
以上问题已经解决!

错误的意思是有一个无效的注解
我的实体类的注解写错了。我的是:@XmlRootElement

应该是
@XmlRootElement(name = "VisUsers")

第一开始只以为是这个的错。
无效注解应该是这里的错。
但是这个解决后紧接着就给我说date参数的错误

是由于我的实体类中有date类型,为sql date
将sql date 改成 util date 就不会有这个问题了

其他的代码都是正确的。

lcj_up 2009-08-23
  • 打赏
  • 举报
回复
等待高手

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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