Java JAXBException: 不是类的有效属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18896536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAXBException: not a valid property on class
提问by chrishern
We have an application which needs to consume an external web service. To do this we have generated the set of Java artifacts from the WSDL via Maven using the wsdl2java goal provided by the cxf-codegen-plugin plugin.
我们有一个需要使用外部 Web 服务的应用程序。为此,我们使用 cxf-codegen-plugin 插件提供的 wsdl2java 目标,通过 Maven 从 WSDL 生成了一组 Java 工件。
In the application we want to set the endpoint to use for the web service call at runtime (to cater for different web service endpoint URLs in test environments) and so have written some code as follows to do this for us:
在应用程序中,我们希望设置端点以在运行时用于 Web 服务调用(以满足测试环境中不同的 Web 服务端点 URL),因此编写了如下代码来为我们执行此操作:
private <T> T createServiceObject(final Class<T> p_seiClass) throws MalformedURLException {
final Service serviceFactory = Service.create(new URL(wsdlLocation), new QName(targetNamespace, serviceName));
final T service = serviceFactory.getPort(p_seiClass);
((BindingProvider) service).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "endpoint");
return service;
}
When the code runs it fails on the serviceFactory.getPort line with the following execption:
当代码运行时,它在 serviceFactory.getPort 行上失败并显示以下执行:
javax.xml.ws.WebServiceException: class ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponse do not have a property of the name ProcessUIRequestResult
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.<init>(ResponseBuilder.java:512)
at com.sun.xml.internal.ws.client.sei.SEIMethodHandler.buildResponseBuilder(SEIMethodHandler.java:172)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.<init>(SyncMethodHandler.java:86)
at com.sun.xml.internal.ws.client.sei.SEIStub.<init>(SEIStub.java:83)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:641)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:344)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:326)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:364)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:368)
at javax.xml.ws.Service.getPort(Service.java:172)
at com.XXX.XXX.XXX.YYY.integration.facade.jaxws.ProcessUIRequestFacadeJaxws.createServiceObject(ProcessUIRequestFacadeJaxws.java:53)
at com.XXX.XXX.XXX.YYY.integration.facade.jaxws.ProcessUIRequestFacadeJaxws.processUIRequest(ProcessUIRequestFacadeJaxws.java:39)
at com.XXX.XXX.XXX.YYY.integration.facade.jaxws.ProcessUIRequestFacadeJaxwsTest.test(ProcessUIRequestFacadeJaxwsTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.accesspackage YYY.ZZZwebservice.v5.types;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import YYY.ZZZbase.BaseVO;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="ProcessUIRequestResult" type="{http://YYY/ZZZbase/}BaseVO" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"processUIRequestResult"
})
@XmlRootElement(name = "ProcessUIRequestResponse")
public class ProcessUIRequestResponse {
@XmlElement(name = "ProcessUIRequestResult")
protected BaseVO processUIRequestResult;
/**
* Gets the value of the processUIRequestResult property.
*
* @return
* possible object is
* {@link BaseVO }
*
*/
public BaseVO getProcessUIRequestResult() {
return processUIRequestResult;
}
/**
* Sets the value of the processUIRequestResult property.
*
* @param value
* allowed object is
* {@link BaseVO }
*
*/
public void setProcessUIRequestResult(BaseVO value) {
this.processUIRequestResult = value;
}
public ProcessUIRequestResponse withProcessUIRequestResult(BaseVO value) {
setProcessUIRequestResult(value);
return this;
}
}
0(ParentRunner.java:53)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.xml.bind.JAXBException: ProcessUIRequestResult is not a valid property on class ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponse
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:954)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.<init>(ResponseBuilder.java:501)
... 37 more
At the bottom I can see javax.xml.bind.JAXBException: ProcessUIRequestResult is not a valid property on class ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponsewhich suggests that something is wrong with the generated ProcessUIRequestResponse.java file.
在底部我可以看到javax.xml.bind.JAXBException: ProcessUIRequestResult is not a valid property on class ZZZ.YYYwebservice.v5.types.ProcessUIRequestResponse这表明生成的 ProcessUIRequestResponse.java 文件有问题。
I've looked at that file and can't see anything obvious (ProcessUIRequestResult is defined in the class and has a getter and setter). The class is below:
我查看了那个文件,并没有看到任何明显的东西(ProcessUIRequestResult 是在类中定义的,并且有一个 getter 和 setter)。课程如下:
/**
* This class was generated by Apache CXF 2.5.2 2013-09-26T13:05:17.389+01:00 Generated source version: 2.5.2
*
*/
@WebService(targetNamespace = "http://zzz/yyywebservice/v5/types/", name = "Types")
@XmlSeeAlso({ zzz.yyyentityview.ObjectFactory.class, zzz.yyyview.search.postcode.ObjectFactory.class,
zzz.yyyentityview.validation.ObjectFactory.class, zzz.serializable_dictionary.ObjectFactory.class,
zzz.yyyview.search.app.ObjectFactory.class, zzz.yyybase.ObjectFactory.class, zzz.yyybase.enums.ObjectFactory.class,
zzz.yyyview.uw.ObjectFactory.class, zzz.yyyview.app.ObjectFactory.class, zzz.yyyview.search.bank.ObjectFactory.class,
zzz.yyyview.search.list.ObjectFactory.class, zzz.yyyentityview.app.ObjectFactory.class,
zzz.yyyentityview.client.ObjectFactory.class, ObjectFactory.class })
public interface Types {
@WebResult(name = "ProcessUIRequestResult", targetNamespace = "")
@ResponseWrapper(localName = "ProcessUIRequestResponse", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.ProcessUIRequestResponse")
@RequestWrapper(localName = "ProcessUIRequest", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.ProcessUIRequest")
@WebMethod(operationName = "ProcessUIRequest", action = "http://zzz/yyywebservice/v5/ProcessUIRequest")
public zzz.yyybase.BaseVO processUIRequest(
@WebParam(name = "ProcessUIRequest", targetNamespace = "http://zzz/yyywebservice/v5/types/") zzz.yyybase.BaseVO processUIRequest);
@WebResult(name = "GetActivityStatusEntityResult", targetNamespace = "")
@ResponseWrapper(localName = "GetActivityStatusEntityResponse", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.GetActivityStatusEntityResponse")
@RequestWrapper(localName = "GetActivityStatusEntity", targetNamespace = "http://zzz/yyywebservice/v5/types/", className = "zzz.yyywebservice.v5.types.GetActivityStatusEntity")
@WebMethod(operationName = "GetActivityStatusEntity", action = "http://zzz/yyywebservice/v5/GetActivityStatusEntity")
public zzz.yyybase.ActivityStatusVOBase getActivityStatusEntity(
@WebParam(name = "ProcessUIRequest", targetNamespace = "http://zzz/yyywebservice/v5/types/") zzz.yyybase.BaseVO processUIRequest);
}
Does anyone have any idea what the problem could be? I can't spot anything obvious and have not been able to find any information as to what the issue could be.
有谁知道可能是什么问题?我无法发现任何明显的问题,也无法找到有关问题可能是什么的任何信息。
Thanks for your help in advance.
提前感谢您的帮助。
EDIT - UPDATE ON 20/09 BASED ON LORENZO'S ANSWER
编辑 - 20/09 更新基于洛伦佐的回答
Unfortunately the web service is a third party service and I don't have access to modify the XSDs. I used the server URL of the WSDL when generating the Java from it.
不幸的是,Web 服务是第三方服务,我无权修改 XSD。从中生成 Java 时,我使用了 WSDL 的服务器 URL。
However, as a test I modified the generated ProcessUIRequestResponse.java to change the property to start with an uppercase letter to match the WSDL and the same error was thrown.
但是,作为测试,我修改了生成的 ProcessUIRequestResponse.java 以将属性更改为以大写字母开头以匹配 WSDL,并且抛出了相同的错误。
Does anyone have any ideas?
有没有人有任何想法?
FURTHER EDIT on 26/09 TO PROVIDE UPDATES **
26/09 进一步编辑以提供更新 **
I've been doing more investigation into this and have found that it actually looks to be an issue with the way in which the service endpoint interface is generated. This is what is generated:
我一直在对此进行更多调查,并发现它实际上看起来是服务端点接口生成方式的问题。这是生成的:
@XmlSchema(
namespace = "http://www.eijux.com/webservices/",
elementFormDefault = XmlNsForm.QUALIFIED
)
package com.starlims.webservices;
The problem is with the @WebResult annotation and the blank targetNamespace. When I manually edit the class and add what I would expect the targetNamespace to be (based on looking in the XSDs), I can sucessfully invoke the web service.
问题在于 @WebResult 注释和空白的 targetNamespace。当我手动编辑类并添加我期望的 targetNamespace 时(基于查看 XSD),我可以成功调用 Web 服务。
I've looked in the XSDs for any missing namespace definitions or any other obvious errors but I can't spot anything. Does anyone have any pointers as to where the targetNamespace or @WebResult is generated from?
我已经在 XSD 中查找任何缺少的命名空间定义或任何其他明显错误,但我什么也找不到。有没有人知道 targetNamespace 或 @WebResult 是从哪里生成的?
回答by Lorenzo Gatti
Javabean property names are traditionally lowercase. You have a capitalized tag name in your WSDL, i.e. ProcessUIRequestResult, but a lowercase property processUIRequestResultin your class, implied by method names setProcessUIRequestResultand getProcessUIRequestResult.
Javabean 属性名称传统上是小写的。您的 WSDL 中有一个大写的标记名称,即ProcessUIRequestResult,但您的类中有一个小写的属性processUIRequestResult,由方法名称setProcessUIRequestResult和getProcessUIRequestResult暗示。
The WSDL to Java code generation appears correct, but it doesn't imply that other library code respects the WSDL and/or the Java annotation.
WSDL 到 Java 代码生成看起来是正确的,但这并不意味着其他库代码尊重 WSDL 和/或 Java 注释。
Can you make it work with lowercase element names?
你能用小写的元素名称让它工作吗?
回答by Gaucho
It can be a matter of how the wsdl2java is naming the package. If the targetNamespace (wsdl) is in camel case notation, your package needs to be camel case too. E.g.:
这可能是 wsdl2java 如何命名包的问题。如果 targetNamespace (wsdl) 是驼峰式表示法,则您的包也需要是驼峰式。例如:
For targetNamespace="http://your.domain/WebAdminServices/WebSiteMgmt"
对于 targetNamespace="http://your.domain/WebAdminServices/WebSiteMgmt"
package domain.your.webAdminServices.webSiteMgmt; --> WORKS :)
包 domain.your.webAdminServices.webSiteMgmt; --> 作品:)
package domain.your.webadminservices.websitemgmt; --> NOT WORKS :(
包 domain.your.webadminservices.websitemgmt; --> 不工作:(
Hope it helps,
希望能帮助到你,
Luis
路易斯
回答by Amir Jamak
I had similar problem and I found something on this linkyou should try the following:
我遇到了类似的问题,我在此链接上发现了一些内容,您应该尝试以下操作:
- add the package-info.java buildpath
- compile and import the new package-info.java for your service and keep the different services in different services
- Download the new package-info.java file from wsdl
- 添加 package-info.java 构建路径
- 为您的服务编译并导入新的 package-info.java 并将不同的服务保留在不同的服务中
- 从 wsdl 下载新的 package-info.java 文件
回答by Will
A workaround: use jaxws-maven-plugin instead. https://mvnrepository.com/artifact/org.codehaus.mojo/jaxws-maven-plugin
解决方法:改用 jaxws-maven-plugin。https://mvnrepository.com/artifact/org.codehaus.mojo/jaxws-maven-plugin
The same problem happened in my project. cxf can't generate targetNamespace but jaxws can given the same wsdl file.
同样的问题发生在我的项目中。cxf 无法生成 targetNamespace 但 jaxws 可以给出相同的 wsdl 文件。
回答by Eijux
Just add the package-info.java like this:
只需像这样添加 package-info.java :
package-info.java :
包信息.java :
##代码##