尝试在XStream中解组时,我遇到异常。
2014-02-11 16:08:00,022 ERROR - com.healthways.checkservices.codes.XMLTransformer : name : name : name : name
---- Debugging information ----
message : name : name
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : name : name
class : com.healthways.checkservices.beans.ServiceDetailsList
required-type : com.healthways.checkservices.beans.ServiceDetailsList
path : /allServices/name
-------------------------------
2014-02-11 16:08:00,022 ERROR [Ljava.lang.StackTraceElement;@68d91916
2014-02-11 16:08:00,023 ERROR - com.healthways.checkservices.codes.XMLTransformer : com.thoughtworks.xstream.mapper.CannotResolveClassException: name : name**
实际上它一直工作到今天。突然之间,我开始收到这个错误,因为我添加了几个插件到mu = y Eclipse Kepler IDE。 在传递xml之前,我正在完成所有可能的先决条件。我的代码段在下面提到 -
XStream xstream = new XStream(new DomDriver());
xstream.alias("service", ServiceDetails.class);
xstream.alias("allServices", ServiceDetailsList.class);
xstream.addImplicitCollection(ServiceDetailsList.class, "list");
// Serialize the XML to Java object
try {
logger.info( "XML Path : " + CommonConstants.FOLDER_PATH);
File inputXMLFile = new File(CommonConstants.FOLDER_PATH+CommonConstants.INPUT_XML_NAME);
if (inputXMLFile.exists()){
fis = new FileInputStream(inputXMLFile);
//De-serializing XML to Java object
ServiceDetailsList serviceList = new ServiceDetailsList();
try {
serviceList = (ServiceDetailsList)xstream.fromXML(fis);
}catch (CannotResolveClassException crce) {
// TODO Auto-generated catch block
logger.error(crce.getMessage());
}catch (ConversionException ce) {
// TODO Auto-generated catch block
logger.error(ce.getMessage());
logger.error(ce.getStackTrace());
logger.error(ce.getCause());
}
Supporting files------
ServiceDetails.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- edited with XMLSpy v2009 (http://www.altova.com) by kevin m forbes (Healthways) -->
<allServices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="services.xsd">
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpngdevapp01</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpngdevapp03</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpngqaapp02</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpnguatapp01</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpnguatapp01</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpnguatapp01</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpnguatapp02</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpngqaapp01</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpngdevapp02</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
</allServices>
ServiceDetails.java
public class ServiceDetails {
private String name;
private String type;
private String serverName;
private String serverPort;
private String env;
private String appsUsed;
private String url;
private String emailIds;
private String statusCode;
private String statusMsg;
private boolean sendMail;
/**
* @return the sendMail
*/
public boolean isSendMail() {
return sendMail;
}
/**
* @param sendMail the sendMail to set
*/
public void setSendMail(boolean sendMail) {
this.sendMail = sendMail;
}
/**
* @return the env
*/
public String getEnv() {
return env;
}
/**
* @param env the env to set
*/
public void setEnv(String env) {
this.env = env;
}
/**
* @return the appsUsed
*/
public String getAppsUsed() {
return appsUsed;
}
/**
* @param appsUsed the appsUsed to set
*/
public void setAppsUsed(String appsUsed) {
this.appsUsed = appsUsed;
}
/**
* @return the emailIds
*/
public String getEmailIds() {
return emailIds;
}
/**
* @param emailIds the emailIds to set
*/
public void setEmailIds(String emailIds) {
this.emailIds = emailIds;
}
/**
* @return the statusCode
*/
public String getStatusCode() {
return statusCode;
}
/**
* @param statusCode the statusCode to set
*/
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
/**
* @return the statusMsg
*/
public String getStatusMsg() {
return statusMsg;
}
/**
* @param statusMsg the statusMsg to set
*/
public void setStatusMsg(String statusMsg) {
this.statusMsg = statusMsg;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the serverName
*/
public String getServerName() {
return serverName;
}
/**
* @param serverName the serverName to set
*/
public void setServerName(String serverName) {
this.serverName = serverName;
}
/**
* @return the serverPort
*/
public String getServerPort() {
return serverPort;
}
/**
* @param serverPort the serverPort to set
*/
public void setServerPort(String serverPort) {
this.serverPort = serverPort;
}
/**
* @return the url
*/
public String getUrl() {
return url;
}
/**
* @param url the url to set
*/
public void setUrl(String url) {
this.url = url;
}
}
ServiceDetailsList.java
public class ServiceDetailsList {
private List<ServiceDetails> list;
public ServiceDetailsList(){
list = new ArrayList<ServiceDetails>();
}
public void add(ServiceDetails sd){
list.add(sd);
}
public List<ServiceDetails> getList(){
return list;
}
}
对于这个问题的任何专家建议,我将不胜感激。 提前谢谢。
答案 0 :(得分:0)
查看“ServiceDetails.xml”后。我注意到它不是有效的...没有&lt; service&gt;由第二个&lt; name&gt; ....包围的开始和结束标记。&lt; sendMail&gt;标签..所以,这是给出例外..首先检查它..纠正它后没有给出例外...使用以下xml而不是上面的
<?xml version="1.0" encoding="utf-8"?>
<!-- edited with XMLSpy v2009 (http://www.altova.com) by kevin m forbes (Healthways) -->
<allServices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="services.xsd">
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpngdevapp01</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpngdevapp03</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpngqaapp02</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpnguatapp01</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpnguatapp01</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpnguatapp01</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpnguatapp02</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>GoogleSvc</name>
<type>MB</type>
<serverName>corpngqaapp01</serverName>
<serverPort>7080</serverPort>
<env>QA</env>
<appsUsed>CIS</appsUsed>
<url>http://www.google.co.in</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
<service>
<name>FlipKartSvc</name>
<type>WCF</type>
<serverName>corpngdevapp02</serverName>
<serverPort>7080</serverPort>
<env>DEV</env>
<appsUsed>CIS</appsUsed>
<url>http://www.flipkart.com/</url>
<emailIds>ashish.kashyap12@gmail.com</emailIds>
<statusCode/>
<statusMsg/>
<sendMail>true</sendMail>
</service>
</allServices>
如果您遇到任何问题,请告诉我