<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
热部署慎用,导致一些的类,实例不匹配问题
- 相同的代码,本地main 方法测试与通过spring 容器调用,执行出不同的结果
public static void main(String[] args) throws Exception {
XStream xStream = new XStream(new XppDriver(new XmlFriendlyReplacer("_-", "_")));
String path = "e:/bw/20200813162829RECEIVE.txt";
path ="e:/bw/20200813162829RECEIVE.LOCKEXAMX";
String packagePath = "com.xx.biz.bean.xml.*";
ChkLockInfoHgSgSjReceive hgSgSjReceive =
XstreamUtil.xml2Object(path,ChkLockInfoHgSgSjReceive.class,packagePath);
}
源码定位:xstream 跟踪 map 的key 为class 类型
private ImplicitCollectionMapperForClass getOrCreateMapper(Class definedIn) {
ImplicitCollectionMapperForClass mapper = (ImplicitCollectionMapperForClass)classNameToMapper
.get(definedIn);
if (mapper == null) {
mapper = new ImplicitCollectionMapperForClass(definedIn);
classNameToMapper.put(definedIn, mapper);
}
return mapper;
}
建议map key 尽量不是使用class 类型,海量源码,一点点debug 测试,最终定位原因
spring-boot-devtools 热部署 导致 产生不同实例,最终导致key 不匹配,程序执行异常