ClassCastException when reading from Infinispan cache after redistribution on Wildfly 8.2

I have a simple local Infinispan cache (also tried distributed cache) on Wildfly 8.2. Everything works fine until I reinstall my .WAR. After reinstalling my .WAR, I get the following error:

Caused by: java.lang.ClassCastException: my.package.MyClass cannot be cast to my.package.MyClass

Full stack: https://gist.github.com/bagges/07af1842a874f7c99ef3

I am browsing Cache in a CDI Bean as follows:

@Path("/mypath")
@Stateless
public class MyServiceClass {

    @Resource(lookup = "java:jboss/infinispan/myContainer")
    private CacheContainer container;

    private Cache<Integer, MyCacheObject> myCache;

    @PostConstruct
    public void start() {
        myCache = container.getCache("myCache");
    }

    @GET
    public String get() {
        if(!myCache.containsKey(1)) {
            myCache.put(1, new MyCacheObject(1, "Hello Cache"));
        }
        return myCache.get(1).getName();
    }
}

Wildfly-Config:

<cache-container name="myContainer" jndi-name="java:jboss/infinispan/myContainer" start="EAGER">
    <local-cache name="myCache"/>
</cache-container>

I know that the error occurred due to different class loaders. Infinispan tries to pass an object stored in a previous classloader that cannot work. But how to avoid this?

+4
source share
2 answers

start = "EAGER". . WildFly 9, .

, ( ). , . .

@Resource(lookup = "java:jboss/infinispan/cache/myContainer/myCache")
private Cache<Integer, MyCacheObject> myCache;

, ref-ref, jndi, , .

+2

, store-as-binary Infinispan, , , GlobalConfiguration:

Cache appSpecificCache = cacheFromJndi.getAdvancedCache().with(applicationClassLoader)
0

All Articles