The following code worked perfectly in JBoss EAP 6.2 with the bundled Infinipan 5.2.7
public class CacheManager {
@Resource(lookup="java:jboss/infinispan/container/my-cache")
private EmbeddedCacheManager myCacheManager;
@Produces
@StageCache
@ApplicationScoped
public Cache<StageKey, Stage> stageCache() {
return myCacheManager.getCache("stage-cache");
}
}
my-cache is defined in standalone.xml:
<cache-container name="my-cache" default-cache="my-cache-default">
<local-cache name="my-cache-default"/>
<local-cache name="stage-cache">
<file-store preload="true" passivation="false" purge="false"/>
</local-cache>
....
The Cache is then Injected in another class using:
@Inject
@StageCache
Cache<StageKey, Stage> stageCache;
But, when using the injected cache, an exception is thrown:
...
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_40]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_40]
at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:40) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.proxies.AsyncCache$BasicCache$BasicCache$BatchingCache$Cache$ConcurrentMap$FilteringListenable$Lifecycle$Listenable$Map$257467401$Proxy$_$$_WeldClientProxy.put(Unknown Source) [weld-core-impl-2.1.2.Final.jar:]
...
Any ideas why this happens? Using the cache without Cache injection by doing myCacheManager.getCache("stage-cache").put(...) works fine.