I have a simple Infinispan local-cache (also tried distributed cache) on Wildfly 8.2. Everything is working fine until I do redeployment of my .WAR. After redeployment of my .WAR I get the following error:
Caused by: java.lang.ClassCastException: my.package.MyClass cannot be cast to my.package.MyClass
Full stacktrace: https://gist.github.com/bagges/07af1842a874f7c99ef3
I lookup the Cache in a CDI Bean like this:
@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 occured because off different class loaders. Infinispan tries to cast the entity stored with the previous classloader which cannot work. But how to avoid this?