求高人帮忙解决异常Exception in thread "main" java.lang.NoSuchMethodError:
有以下异常,求大家帮忙解决一下:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.Sets.newIdentityHashSet()Ljava/util/Set;
at org.glassfish.jersey.model.internal.CommonConfig.<init>(CommonConfig.java:215)
at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:144)
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:423)
at org.glassfish.jersey.client.JerseyClientBuilder.<init>(JerseyClientBuilder.java:72)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:116)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:206)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
at renlai.client.pc.service.MenberBase.MenberBaseService.menberLogin(MenberBaseService.java:25)
at renlai.client.pc.service.MenberBase.MenberBaseService.main(MenberBaseService.java:47)
1、调用方法处:Client客户端,这是编写了一个main方法测试的时候出错了
public class MenberBaseService {
//生成客户端对象
Client client=ClientBuilder.newClient();
//定义路径
String strUrl="http://localhost:6060/GRZYService/services";
//获取当前对象的webTarget
WebTarget target=client.target(strUrl);
//获取对应的webService类
WebTarget resouce=target.path("MenberBaseService");
//获得对应的webService方法
WebTarget menberLogin=resouce.path("menberLogin/"+"1000006973");
//响应类型
Invocation.Builder builder=menberLogin.request(MediaType.APPLICATION_JSON);
public MenberBase menberLogin(){
MenberBase menberBase=null;
//获取响应对象
Response response=builder.get();
System.out.println(response.getStatus());
//获取响应内容
//String menberResult=response.readEntity(String.class);
System.out.println();
return menberBase;
}
public static void main(String[] args) {
MenberBaseService mbs=new MenberBaseService();
MenberBase mb=mbs.menberLogin();
System.out.println(mb.getMbEmail());
}
2、被调用的方法处:webserivce
/**
* @author Cavion
* 2013-12-24
*/
@Path("MenberBaseService")
public class MenberBaseService {
/**
* 根据id查询,用于登陆
* @param mid
* @return
*/
@GET
@Path("menberLogin/{mid}")
@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public MenberBase findByid(@PathParam("mid") String mid){
String hql="from MenberBase mb where mb.mbId=?";
MenberBase menberBase=(MenberBase) HibernateBase.findById(hql, mid);
return menberBase;
}
3、webservice的实体类:引用的是hibernate
package renlai.cavion.grzy.hibernate.domain.Menber;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
/**
* MenberBase entity. @author MyEclipse Persistence Tools
*/
@XmlRootElement
public class MenberBase implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = -1347079687110430853L;
private String mbId;
private MenberNation menberNation;
private String mbPwd;
private String mbName;
private String mbNickName;
private Integer mbSexy;
private Timestamp mbBorn;
private String mbPhone;
private String mbQq;
private String mbPwdEmail;
private String mbEmail;
private String mbImagePath;
//private Set menberAddresses = new HashSet(0);
// Constructors
/** default constructor */
public MenberBase() {
}
/** minimal constructor */
public MenberBase(MenberNation menberNation, String mbPwd,
String mbNickName, Integer mbSexy, String mbEmail) {
this.menberNation = menberNation;
this.mbPwd = mbPwd;
this.mbNickName = mbNickName;
this.mbSexy = mbSexy;
this.mbEmail = mbEmail;
}
/** full constructor */
public MenberBase(MenberNation menberNation, String mbPwd, String mbName,
String mbNickName, Integer mbSexy, Timestamp mbBorn,
String mbPhone, String mbQq, String mbPwdEmail, String mbEmail,
String mbImagePath, Set menberAddresses) {
this.menberNation = menberNation;
this.mbPwd = mbPwd;
this.mbName = mbName;
this.mbNickName = mbNickName;
this.mbSexy = mbSexy;
this.mbBorn = mbBorn;
this.mbPhone = mbPhone;
this.mbQq = mbQq;
this.mbPwdEmail = mbPwdEmail;
this.mbEmail = mbEmail;
this.mbImagePath = mbImagePath;
//this.menberAddresses = menberAddresses;
}
// Property accessors
public String getMbId() {
return this.mbId;
}
public void setMbId(String mbId) {
this.mbId = mbId;
}
public MenberNation getMenberNation() {
return this.menberNation;
}
public void setMenberNation(MenberNation menberNation) {
this.menberNation = menberNation;
}
public String getMbPwd() {
return this.mbPwd;
}
public void setMbPwd(String mbPwd) {
this.mbPwd = mbPwd;
}
public String getMbName() {
return this.mbName;
}
public void setMbName(String mbName) {
this.mbName = mbName;
}
public String getMbNickName() {
return this.mbNickName;
}
public void setMbNickName(String mbNickName) {
this.mbNickName = mbNickName;
}
public Integer getMbSexy() {
return this.mbSexy;
}
public void setMbSexy(Integer mbSexy) {
this.mbSexy = mbSexy;
}
public Timestamp getMbBorn() {
return this.mbBorn;
}
public void setMbBorn(Timestamp mbBorn) {
this.mbBorn = mbBorn;
}
public String getMbPhone() {
return this.mbPhone;
}
public void setMbPhone(String mbPhone) {
this.mbPhone = mbPhone;
}
public String getMbQq() {
return this.mbQq;
}
public void setMbQq(String mbQq) {
this.mbQq = mbQq;
}
public String getMbPwdEmail() {
return this.mbPwdEmail;
}
public void setMbPwdEmail(String mbPwdEmail) {
this.mbPwdEmail = mbPwdEmail;
}
public String getMbEmail() {
return this.mbEmail;
}
public void setMbEmail(String mbEmail) {
this.mbEmail = mbEmail;
}
public String getMbImagePath() {
return this.mbImagePath;
}
public void setMbImagePath(String mbImagePath) {
this.mbImagePath = mbImagePath;
}
/*public Set getMenberAddresses() {
return this.menberAddresses;
}
public void setMenberAddresses(Set menberAddresses) {
this.menberAddresses = menberAddresses;
}
*/
}
4、对应的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="ranlai.cavion.grzy.hibernate.domain.Menber.MenberBase" table="MenberBase" schema="dbo" catalog="Menber">
<id name="mbId" type="java.lang.String">
<column name="MB_ID" />
</id>
<many-to-one name="menberNation" class="ranlai.cavion.grzy.hibernate.domain.Menber.MenberNation" fetch="select">
<column name="MB_NationCope" not-null="true" />
</many-to-one>
<property name="mbPwd" type="java.lang.String">
<column name="MB_Pwd" not-null="true" />
</property>
<property name="mbName" type="java.lang.String">
<column name="MB_Name" />
</property>
<property name="mbNickName" type="java.lang.String">
<column name="MB_NickName" not-null="true" />
</property>
<property name="mbSexy" type="java.lang.Integer">
<column name="MB_Sexy" not-null="true" />
</property>
<property name="mbBorn" type="java.sql.Timestamp">
<column name="MB_Born" length="23" />
</property>
<property name="mbPhone" type="java.lang.String">
<column name="MB_Phone" />
</property>
<property name="mbQq" type="java.lang.String">
<column name="MB_QQ" />
</property>
<property name="mbPwdEmail" type="java.lang.String">
<column name="MB_PwdEmail" />
</property>
<property name="mbEmail" type="java.lang.String">
<column name="MB_Email" not-null="true" />
</property>
<property name="mbImagePath" type="java.lang.String">
<column name="MB_ImagePath" />
</property>
<!-- <set name="menberAddresses" inverse="true" cascade="none" lazy="false">
<key>
<column name="MB_ID" not-null="true" />
</key>
<one-to-many class="ranlai.cavion.grzy.hibernate.domain.Menber.MenberAddress" />
</set> -->
</class>
</hibernate-mapping>
在webservice中执行是成功的,所以估计是传输到Client中时出的错误,求高手帮忙解决一下,在这弄了好长时间了,就是不知道问题在那!在此谢谢各位大神了!
[解决办法]
是不是jar包版本不对啊?
[解决办法]
检查下,jar包导入成功了吗?