gpt4 book ai didi

java - 带有实体类的 SOAP

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:39 25 4
gpt4 key购买 nike

我有这个实体类:

package com.model;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity
import com.model.BaseEntity;
import com.model.CustomerPK;

@Entity
@Table(name = "CUSTOMER")
public class Customer extends BaseEntity {

private static final long serialVersionUID = -625869124375935833L;

@EmbeddedId
private CustomerPK id;

@Column(name = "NAME", length = 70, nullable = true)
private String name;

@Column(name = "PHONE", length = 20, nullable = true)
private String phone;

@Column(name = "ADDRESS", length = 40, nullable = true)
private String address;

@Column(name = "CITY", length = 30, nullable = true)
private String city;

....

}

我有这个 Web 服务类:

package com.ws;

import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
import com.servico.WSService;

import com.model.Customer;


@WebService(serviceName = "customerWS")
public class CustomerWS {

@Inject
private WSService wss;

@WebMethod(operationName = "validateCustomer")
public List<String> validateCustomer(
@XmlElement(name = "customer", required = true) Customer customer) {
return wss.validateCustomer(customer);
}
}

当我尝试启动服务时,显示此错误:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://--.--.-----.-----.-----.----.----.--/}baseEntity". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at ------.BaseEntity
at ------.model.BaseEntity

this problem is related to the following location:
at ------.model.BaseEntity

我无法编辑 BaseEntity 类。有没有一种方法可以在不注释 BaseEntity 类的情况下创建 Web 服务?

编辑:

我不想使用 MOXy 框架,因为我已经在线有了 Web 服务。我的问题是我是否只能编码 Customer 类,而不编码她的 BaseEntity 类。附加信息:我的客户端和我的 Web 服务可以访问 Customer 类所在的同一包。

最佳答案

如果你可以使用MOXy,那么就有option

如果您无法为类添加注释

MOXy 提供了一个外部映射文档扩展,可用于将 JAXB 元数据应用到无法更改的类。

<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="**com.common**">
<java-types>
<java-type name="City">
<xml-type name="city2"/>
</java-type>
</java-types>
</xml-bindings>

关于java - 带有实体类的 SOAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28483913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com