JBoss Community

ClassCastException with Infinispan using multiple applications

created by Randy Nott in JBoss AS 7 Development - View the full discussion

I'm getting a ClassCastException when using an Infinispan cache to share data between two web applications, A and B running in the same JBoss AS-7 instance. Application A writes to the cache while application B reads from it. Application B fails on the read as the value is tied to the classloader of application A.

 

I've tried this with both standalone and HA configurations in JBoss AS-7.0.2, defining the cache as local, then distributed, with similar results. Here is my cache configuration (standalone-preview-ha.xml):

 


<cache-container name="foo-cache" default-cache="foo">
  <distributed-cache mode="ASYNC" name="foo" start="EAGER">
      <eviction strategy="NONE"/>
  </distributed-cache>
</cache-container>

 

 

I'm injecting the cache into both web applications using CDI with the following producer:

 


@Resource(mappedName="java:jboss/infinispan/foo-cache") 
private CacheContainer container;

@FooCache
@Produces @ApplicationScoped
Cache<String, Foo> fooCache() {
    return container.getCache( "foo" );
}

 

 

I'd prefer that the cache be embedded in the JBoss instance as opposed to remote if this is possible. Does anyone know the recipe for making this work?

Reply to this message by going to Community

Start a new discussion in JBoss AS 7 Development at Community