事先抱歉我的英语不好。
在多线程环境中将字符串解组为LocalDateTime时遇到问题。我使用org.apache.cxf版本2.7.7
生成了java classe(ActivityData)当我不时地调试应用程序时,字符串的年份已经损坏,在年初有一些奇怪的值(例如722008-01-01,A2008-01-01,12008-01-01当我与像肥皂ui这样的客户进行通话时,日期格式正确。 localDateAdapter由批处理应用程序中的多个线程调用。当我重新运行批处理时,相同的调用成功并且其他调用失败,解析错误是不可预测的。问题仅发生在开始日期,java对象中的结束日期始终格式良好
我尝试同步该方法,但它并没有改变一件事。
提前感谢您的帮助
这是我的LocalDateTimeAdapter的代码
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
public synchronized LocalDateTime unmarshal(String v) {
if (StringUtils.isNotBlank(v)) {
try {
return LocalDateTime.parse(v, DateTimeFormatter.ISO_DATE_TIME);
} catch (Exception exception) {
throw new IllegalArgumentException("Parsing problem in the localDateTime for string : " + v);
}
}
return null;
}
public String marshal(LocalDateTime v) {
if (v != null) {
return v.toString();
}
return StringUtils.EMPTY;
}
}
生成的类:
绑定文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_1.xsd"
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:globalBindings>
<jaxb:serializable uid="1"/>
<xjc:javaType
name="java.time.LocalDate"
xmlType="xs:date"
adapter="be.fgov.minfin.vies.adapter.LocalDateAdapter"/>
<xjc:javaType
name="java.time.LocalDateTime"
xmlType="xs:dateTime"
adapter="be.fgov.minfin.vies.adapter.LocalDateTimeAdapter"/>
</jaxb:globalBindings>
</jaxb:bindings>
生成的类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ActivityData", propOrder = {
"beginDate",
"endDate"
})
public class ActivityData
implements Serializable
{
private final static long serialVersionUID = 1L;
@XmlElement(type = String.class)
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
@XmlSchemaType(name = "dateTime")
protected LocalDateTime beginDate;
@XmlElement(type = String.class)
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
@XmlSchemaType(name = "dateTime")
protected LocalDateTime endDate;
/**
* Gets the value of the beginDate property.
*
* @return
* possible object is
* {@link String }
*
*/
public LocalDateTime getBeginDate() {
return beginDate;
}
/**
* Sets the value of the beginDate property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setBeginDate(LocalDateTime value) {
this.beginDate = value;
}
/**
* Gets the value of the endDate property.
*
* @return
* possible object is
* {@link String }
*
*/
public LocalDateTime getEndDate() {
return endDate;
}
/**
* Sets the value of the endDate property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEndDate(LocalDateTime value) {
this.endDate = value;
}
}