Gunnar,

While WF doesn't include infinispan-cdi integration, you can inject
Infinispan caches defined within the Infinispan subsystem as standard
EE resources via the their JNDI bindings.  This approach has the
advantage of container-managed lifecycle of the cache, even when
referenced by multiple deployments.

e.g.
@Resource(lookup = "java:jboss/infinispan/cache/foo/bar")
private Cache<?, ?> cache; // References the "bar" cache of the "foo"
cache container

or

@Resource(lookup = "java:jboss/infinispan/cache/foo/default")
private Cache<?, ?> cache; // References the default cache of the
"foo" cache container

Unfortunately, a long standing weld integration bug prevents @Resource
lookups from working correctly when the containing class is
instrumented by CDI.  To workaround this, move the JNDI lookup to a
<resource-ref/> or <resource-env-ref/> in your deployment descriptor
and reference your cache resource via its reference name.

e.g.
<resource-env-ref>
    <resource-env-ref-name>my-cache<resource-env-ref-name>
    <resource-env-ref-type>org.infinispan.Cache<resource-env-ref-type>
    <lookup-name>java:jboss/infinispan/cache/foo/bar</lookup-name>
</resource-env-ref>

@Resource(name = "my-cache")
private Cache<?, ?> cache;

Paul
On Wed, Dec 5, 2018 at 3:47 AM Gunnar Morling <gun...@hibernate.org> wrote:
>
> Hey,
>
> I was trying to configure and inject an Infinispan cache through CDI,
> running on WildFly 14, using the Infinispan modules provided by the
> server.
>
> While I'm not sure whether that's something supported or recommended,
> I found this preferable over adding Infinispan another time as part of
> the deployment. I couldn't find any recent info on doing this (would
> love any pointers, though), so here's my findings, in case it's
> interesting for others:
>
> * A jboss-deployment-structure.xml file is needed for adding the
> dependencies to the modules org.infinispan and org.infinispan.commons
> * Unlike the core module, org.infinispan:infinispan-cdi-embedded isn't
> part of WF, so it must be added to the deployment
> * The transitive dependency from infinispan-cdi-embedded to
> org.infinispan:infinispan-commons must be excluded, otherwise linking
> errors will occur
>
> Perhaps a small example of this could be added to the Infinispan docs?
>
> Btw. I also couldn't find an example for configuring a cache through
> jboss-cli.sh, perhaps that's something to consider, too?
>
> Cheers,
>
> --Gunnar
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev
_______________________________________________
infinispan-dev mailing list
infinispan-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev

Reply via email to