MyEclipse rest webservice (Jersey)使用 问题总结


java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

从http://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle 下载对应版本,放到WebRoot/WEB-INF/lib下,右击,并Add to Build Path

java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor

  • 下载:asm-commons-3.3.jar  http://www.java2s.com/Code/Jar/a/Downloadasmcommons33jar.htm 
  • 下载:asm-3.3.jar  http://www.java2s.com/Code/Jar/a/Downloadasm33jar.htm 
  • 下载:asm-tree-3.3.jar  http://www.java2s.com/Code/Jar/a/Downloadasmtree33jar.htm 
加入Build Path

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

restful项目却没有定义webservice,定义一个webservice即可。

No provider classes found.

这个是提示信息,不是错误信息。
把web.xml 里 Jersey servlet 从“com.sun.jersey.spi.container.servlet.ServletContainer” 改为 “com.sun.jersey.spi.spring.container.servlet.SpringServlet“.
另外在类上加@Provider注解,如:
package com.cn;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.ext.Provider;
@Provider
@Path("/helloWS")
public class HelloService {

	@GET
	@Path("/hello{name}")
	@Produces("application/json")
	public String sayhello(@QueryParam("name") String name) {
		throw new UnsupportedOperationException("Not yet implemented.");
	}
}


java.lang.ClassNotFoundException: com.sun.jersey.spi.spring.container.servlet.SpringServlet

下载:http://www.java2s.com/Code/Jar/j/Downloadjerseyspring15jar.htm

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

在<servlet> (含com.sun.jersey.spi...)里加
  	<init-param>
   		<param-name>com.sun.jersey.config.property.packages</param-name>
   		<param-value>com.cn</param-value>
	</init-param>

javax.servlet.ServletException: Error allocating a servlet instance

重启Tomcat

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

把方法上的@Produces(MediaType.TEXT_XML)  改为@Produces("application/json")

and MIME media type application/json was not found

下载:http://owlike.github.io/genson/ 

Servlet Jersey REST Service is not available(页面提示这个错误)

Failed to classload type while reading annotation metadata. This is a non-fatal error, but certain annotation metadata may be unavailable.
java.lang.ClassNotFoundException: javax.ws.rs.Path(控制台提示这个错误)
下载:http://www.java2s.com/Code/Jar/j/Downloadjsr311api111jar.htm

无法处理application/x-www-form-urlencoded;charset=UTF-8

jquery的ajax请求改用post,content-type设置为:application/json

Could not deserialize to type class com.sun.jersey.api.representation.Form

改Content-Type和Consumes为MediaType.APPLICATION_FORM_URLENCODE 及application/x-www-form-urlencode
    <script>
$("#btn").click(function(){
	$.ajax({
	    url: "rest/ApasInfoPush/Push/",
	    type: "post",
	    dataType: "json",
	    data: {
	    	APAS_INFO_UNID:$("select[name=APAS_INFO_UNID]").val(),
	    	HANDLESTATE:$("#input[name=HANDLESTATE]").val(),
	    	MESSAGE:$("input[name=MESSAGE]").val(),
	    	TO_USERID:$("input[name=TO_USERID]").val(),
	    	TO_USERNAME:$("input[name=TO_USERNAME]").val()
	    },
	    headers: {'Content-Type': 'application/x-www-form-urlencoded','Accept': ''},
	    success: function (res) {
	        if (res.status == 1) {
	            window.location.reload();
	        } else {
	            alert(res.message);
	        }
	    }
	});
});
    </script>

	@POST
	@Path("/Push/")
	@Produces({ MediaType.APPLICATION_JSON })
	@Consumes({ MediaType.APPLICATION_FORM_URLENCODED  })


The request sent by the client was syntactically incorrect (Bad Request).

这个看不出来错误,配置一下web.xml,加
	<init-param>
	  <param-name>com.sun.jersey.config.feature.TracePerRequest</param-name>
	  <param-value>true</param-value>      
	</init-param>
ajax请求加:
   headers: {
                "X-Jersey-Trace-Accept":true
            },
这时看到服务端错误再处理。

java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I

Struts2 Core Libraries下有个antlr-2.7.2.jar
Hibernate 4.1 Core Libraries有个antlr-2.7.7.jar
删除版本低的一个。
要删除的地方:

MyEclise安装目录删除低版本的jar。
workspace里搜索antlr-2.7.2.jar并删除。

Lock wait timeout exceeded; try restarting transaction

参考:
http://stackoverflow.com/questions/5836623/getting-lock-wait-timeout-exceeded-try-restarting-transaction-even-though-im

1) 进入mysql
mysql -u your_user -p
2) 查看锁定的表
mysql> show open tables where in_use>0;
3) 查看当前process,它们有一些是在锁定的表里
mysql> show processlist;
4) Kill 相关process
mysql> kill put_process_id_here;

另外执行:

SET GLOBAL innodb_lock_wait_timeout = 5000; 
SET innodb_lock_wait_timeout = 5000; 

严重: Servlet.service() for servlet [Jersey REST Service] in context with path [/WhrWechat2] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)

删除javax.ws.rs-api-2.0.jar 可以

一些使用参考:
https://theholyjava.wordpress.com/2012/01/31/troubleshooting-jersey-rest-server-and-client/
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程圈子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值