Ignite初探-ignite集成spring boot 类转换异常classCastException

问题描述:

    向ignite cache中保存实体类ClassA的对象然后遍历。junit测试通过,但是启动spring boot 程序通过contoller调用service报错。
java.lang.ClassCastException: domain.PersonData cannot be cast to domain.PersonData
    at com.zeegates.compare.engine.service.impl.DataStoreServiceImpl.lambda$0(DataStoreServiceImpl.java:22) ~[classes/:na]

    at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_131]

出错代码为:

    gniteCache<String, PersonData> cache = ignite.cache(cacheName);
        
        cache.forEach(object->{
            System.out.println(object.getValue().getZwxm());

        });

报错也非常奇怪,后来改成

System.out.println(PersonData.class.getClassLoader());
        IgniteCache<Object, Object> cache = ignite.cache(cacheName);
        
        cache.forEach(object->{
            System.out.println(object.getValue().getClass().getClassLoader());
        });

发现两个并不是同一个类加载器加载.数据结果为:

org.springframework.boot.devtools.restart.classloader.RestartClassLoader@273c110c

sun.misc.Launcher$AppClassLoader@73d16e93


问题明白了。是spring boot的动态加载机制导致的。在pom文件中去掉的dev-tool正常了。

如何让ignite也使用spring boot dev-tool类加载器暂未找到方法。



猜你喜欢

转载自blog.csdn.net/sinianliushui/article/details/79649607