【发布时间】:2016-11-11 06:41:02
【问题描述】:
下面我给出了我想使用 spring requestBody 使用的 xml
<?xml version="1.0" encoding="UTF-8"?>
<UTILITYTYPE CODE="1">
<ALERT_INFORMATION>
<ALERT_SRC>MODEM</ALERT_SRC>
<MODEM_SERIAL_NUMBER>B00101</MODEM_SERIAL_NUMBER>
<G1>GET06253</G1>
<METER_MFR_NAME>SECURE</METER_MFR_NAME>
<METER_TYPE>FEEDER</METER_TYPE>
<DISCOM>MGVCL</DISCOM>
<ALERT_CODE>73</ALERT_CODE>
<ALERT_STATUS>0</ALERT_STATUS>
<ALERT_DESCRIPTION>11KV RAIYOLIFEEDER Power Failed</ALERT_DESCRIPTION>
<ALERT_GENERATED_DATE_TIME>06-07-2016 15:16:06</ALERT_GENERATED_DATE_TIME>
</ALERT_INFORMATION>
</UTILITYTYPE>
我的主要问题是我想将 XML 参数映射到 java bean。我已经创建了下面给出的 bean
@XmlRootElement(name="UTILITYTYPE")
public class UtilityType implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@XmlAttribute(name="ALERT_INFORMATION")
private List<AlertInformation> alertInformationBean;
public List<AlertInformation> getAlertInformationBean() {
return alertInformationBean;
}
public void setAlertInformationBean(List<AlertInformation> alertInformationBean) {
this.alertInformationBean = alertInformationBean;
}
}
另一个豆子是
@XmlRootElement
public class AlertInformation implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@XmlAttribute(name="MODEM_SERIAL_NUMBER")
private String modelSerialNo;
@XmlAttribute(name="G1")
private String generate;
@XmlAttribute(name="METER_MFR_NAME")
private String meterName;
@XmlAttribute(name="METER_TYPE")
private String meterType;
@XmlAttribute(name="DISCOM")
private String disCom;
@XmlAttribute(name="ALERT_CODE")
private int alertCode;
@XmlAttribute(name="ALERT_STATUS")
private int alertStatus;
@XmlAttribute(name="ALERT_DESCRIPTION")
private String alertDesc;
@XmlAttribute(name="ALERT_GENERATED_DATE_TIME")
private String alertDatetime;
@XmlAttribute(name="ALERT_SRC")
private String alertSrc;
消耗响应的弹簧控制器如下所示
@RequestMapping(value="/getMdasInformation" ,method=RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody List<ResponseBean> getMdasDetails(@RequestBody UtilityType mdasUBean){
}
以下是我得到的异常
@XmlAttribute/@XmlValue need to reference a Java type that maps to text in XML.
this problem is related to the following location:
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertInformationBean"
this problem is related to the following location:
at public java.util.List com.cnetinfotech.rec.beans.UtilityType.getAlertInformationBean()
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertCode"
this problem is related to the following location:
at public int com.cnetinfotech.rec.beans.AlertInformation.getAlertCode()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private int com.cnetinfotech.rec.beans.AlertInformation.alertCode
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertDatetime"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getAlertDatetime()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.alertDatetime
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertDesc"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getAlertDesc()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.alertDesc
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertSrc"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getAlertSrc()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.alertSrc
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertStatus"
this problem is related to the following location:
at public int com.cnetinfotech.rec.beans.AlertInformation.getAlertStatus()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private int com.cnetinfotech.rec.beans.AlertInformation.alertStatus
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "disCom"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getDisCom()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.disCom
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "generate"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getGenerate()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.generate
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "meterName"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getMeterName()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String
com.cnetinfotech.rec.beans.AlertInformation.meterName
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "meterType"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getMeterType()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.meterType
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "modelSerialNo"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getModelSerialNo()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.modelSerialNo
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
] with root cause
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 12 counts of IllegalAnnotationExceptions
@XmlAttribute/@XmlValue need to reference a Java type that maps to text in XML.
this problem is related to the following location:
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertInformationBean"
this problem is related to the following location:
at public java.util.List com.cnetinfotech.rec.beans.UtilityType.getAlertInformationBean()
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertCode"
this problem is related to the following location:
at public int com.cnetinfotech.rec.beans.AlertInformation.getAlertCode()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private int com.cnetinfotech.rec.beans.AlertInformation.alertCode
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertDatetime"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getAlertDatetime()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.alertDatetime
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertDesc"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getAlertDesc()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.alertDesc
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertSrc"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getAlertSrc()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.alertSrc
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "alertStatus"
this problem is related to the following location:
at public int com.cnetinfotech.rec.beans.AlertInformation.getAlertStatus()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private int com.cnetinfotech.rec.beans.AlertInformation.alertStatus
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "disCom"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getDisCom()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.disCom
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "generate"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getGenerate()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.generate
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "meterName"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getMeterName()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.meterName
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "meterType"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getMeterType()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.meterType
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
Class has two properties of the same name "modelSerialNo"
this problem is related to the following location:
at public java.lang.String com.cnetinfotech.rec.beans.AlertInformation.getModelSerialNo()
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
this problem is related to the following location:
at private java.lang.String com.cnetinfotech.rec.beans.AlertInformation.modelSerialNo
at com.cnetinfotech.rec.beans.AlertInformation
at private java.util.List com.cnetinfotech.rec.beans.UtilityType.alertInformationBean
at com.cnetinfotech.rec.beans.UtilityType
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter.getJaxbContext(AbstractJaxb2HttpMessageConverter.java:111)
at org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter.createUnmarshaller(AbstractJaxb2HttpMessageConverter.java:79)
at org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter.readFromSource(Jaxb2RootElementHttpMessageConverter.java:103)
at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.readInternal(AbstractXmlHttpMessageConverter.java:61)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:159)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:154)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:149)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:100)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:174)
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:237)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
但我无法使用它并给出 404 错误。请帮我解决它。非常感谢。
【问题讨论】:
-
您在控制台中看到任何异常吗?你能把它添加到帖子中吗?
-
没有它给出 404 错误并且没有实际消费
-
好吗?能否请您添加控制器代码和用于使用 API 的 URL?
-
实际上代码在我的本地机器中,我还添加了 .请检查你会找到网址
-
我需要查看 Controller 类代码,而不仅仅是 getMdasDetails()。而且我没有在您的帖子中看到返回 404 页面的 URL。
标签: java xml spring spring-mvc