1 2 Previous Next 19 Replies Latest reply on Jul 23, 2018 3:30 AM by jurevi

    Wildfly 12 Cache migration error




      I'm trying to update wildfly 11 to 12 but I'm getting strange exception with this method CacheContainer#getCache(java.lang.String).


      When I call this method I get :


      Caused by: org.infinispan.commons.CacheConfigurationException: ISPN000436: Cache 'com/axemble/vdoc/directory/DirectoryManagerBean' has been requested, but no cache configuration exists with that name and no default cache has been set for this container
      at org.infinispan.manager.DefaultCacheManager.wireAndStartCache(DefaultCacheManager.java:611)
      at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:598)
      at org.infinispan.manager.DefaultCacheManager.internalGetCache(DefaultCacheManager.java:462)
      at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:448)
      at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:434)
      at org.jboss.as.clustering.infinispan.DefaultCacheContainer.getCache(DefaultCacheContainer.java:60)
      at com.axemble.commons.cache.DefaultCacheService.getCache(DefaultCacheService.java:98)


      I have this cache-container configuration :


      <subsystem xmlns="urn:jboss:domain:infinispan:5.0">
         <cache-container name="vdoc-cache" default-cache="default">
            <local-cache name="default">


      I found a work around by re set the default cache configuration like it :


      try {
           EmbeddedCacheManager embeddedCacheManager = InitialContext.doLookup("java:jboss/infinispan/container/vdoc-cache");
           org.infinispan.configuration.cache.Configuration c = new ConfigurationBuilder().clustering().cacheMode(CacheMode.LOCAL).build();
           String newCacheName = "default";
           embeddedCacheManager.defineConfiguration(newCacheName, c);
           Cache<String, String> cache = embeddedCacheManager.getCache(newCacheName); // this work
      } catch (NamingException e) {


      It is a bad configuration, bad useage or a bug ?



        • 1. Re: Wildfly 12 Cache migration error

          Can you paste the relevant code from com.axemble.commons.cache.DefaultCacheService.java?

          • 2. Re: Wildfly 12 Cache migration error



            I have the same problem. I have a singleton EJB to startup the caches. This has worked well since wildfly 9 but in wildfly 12 it stopped working. The above workaround works though if I put it in the @PostConstruct below.


            Here is a simple EJB to reproduce the problem.


            public class CacheStartup {
                @Resource(lookup = "java:jboss/infinispan/container/vdoc-cache")
                private CacheContainer cacheContainer;
                public void initializeCaches() {
                 // This line fails
                    Cache<?, ?> cache = cacheContainer.getCache("default");
            • 3. Re: Wildfly 12 Cache migration error

              Hello here the full code :


              package com.axemble.commons.cache;
              import org.infinispan.Cache;
              import org.infinispan.manager.CacheContainer;
              // ...
              public class DefaultCacheService implements CacheService
                public static final String VDOC_CACHE_JNDI_NAME = "java:jboss/infinispan/container/vdoc-cache";
                public static final char SEPARATOR = '/';
                private static final Logger LOG = Logger.getLogger(DefaultCacheService.class);
                private final CacheContainer cacheContainer;
                private static class SingletonHolder
                  private static DefaultCacheService instance = new DefaultCacheService();
                public DefaultCacheService()
                    this.cacheContainer = InitialContext.doLookup(VDOC_CACHE_JNDI_NAME);
                    LOG.debug("Cache container found!");
                  catch (NamingException e)
                    throw new IllegalStateException("Can't get cache " + VDOC_CACHE_JNDI_NAME, e);
                public static DefaultCacheService getInstance()
                  return SingletonHolder.instance;
                // ... 
                private String getRepositoryName(String... repositories)
                  if(repositories.length == 1)
                    return repositories[0];
                  StringBuilder builder = new StringBuilder();
                  for (String repository : repositories)
                  builder.setLength(builder.length()-1); // remove the last separator
                  return builder.toString();
                private  Cache<string, t=""> getCache(String... repositories)
                  return this.cacheContainer.getCache(this.getRepositoryName(repositories)); // exception is here
              • 4. Re: Wildfly 12 Cache migration error

                famaridon Clustering services are only ever started on demand.  Thus the reason your code fails is because your code does not establish a dependency on the requisite Infinispan resources - thus they are not available to your deployment.

                I going to guess that you must be using the "full-ha" profile, otherwise the JNDI lookup of your cache container would fail.  Cache containers (and their JNDI bindings) are started passively when the JGroups channel used by its transport starts.  Because the "full-ha" profile starts the default JGroups channel during server startup (due to a dependency from activemq broadcast/discovery), this lookup succeeds in your code.  However, if you were to run the "ha" profile, the default JGroups channel of the server is not automatically started, and thus your lookup would fail.  Additionally, your calls to getCache(...) fail because the started cache container has no cache configurations defined - as these are also only defined on demand.


                To properly access an Infinispan cache in your application:


                Use a <resource-ref/> or <resource-env-ref/> to make the requisite Infinispan resource available to your deployment specific JNDI namespace.




                You can now lookup the cache directly via the jndi name "java:comp/env/infinispan/mycache".


                private Cache<?, ?> cache;


                Alternatively, though more verbosely, you can obtain the cache via the cache container.  However, this requires not just a dependency on the cache container, but also on the cache configuration (to ensure that it is installed in the cache container).  The primary downside to this approach is that your deployment must now handle the lifecycle of the cache.  This means you cannot (easily) reference the same cache from multiple deployments.





                private EmbeddedCacheManager container;
                private Cache<?, ?> cache;
                public void init() {
                    this.cache = this.container.getCache("mycache");  // The <resource-ref/> to the cache configuration ensures this configuraiton is installed
                public void destroy {
                1 of 1 people found this helpful
                • 5. Re: Wildfly 12 Cache migration error

                  aspan Use the following code instead:

                  public class CacheStartup {
                      @Resource(lookup = "java:jboss/infinispan/cache/vdoc-cache/default")
                      private Cache<?, ?> cache; 
                  • 6. Re: Wildfly 12 Cache migration error

                    Thanks pferraro, got it working with <resource-ref> definitions outlined in your previous answer.

                    • 7. Re: Wildfly 12 Cache migration error

                      Hi and thanks you Paul,


                      I work with Florent Amaridon on the same project. After adding our cache's resource-env-ref, we are now able to lookup and use the cache.



                      • 8. Re: Wildfly 12 Cache migration error

                        Hi Paul! pferraro

                        You mentioned a direct lookup parameter for the cache: @Resource(lookup = "java:jboss/infinispan/cache/vdoc-cache/default")

                        At the same time, I can see in the jboss-cli resource description for a cache, that such parameter in now DEPRECATED and will not be used!!!

                         "jndi-name" => {
                            "type" => STRING,
                            "description" => "The jndi-name to which to bind this cache instance.",
                            "expressions-allowed" => true,
                            "required" => false,
                            "nillable" => true,
                            "min-length" => 1L,
                            "max-length" => 2147483647L,
                            "deprecated" => {
                                     "since" => "6.0.0",
                                     "reason" => "Deprecated. Will be ignored."
                                     "access-type" => "read-write",
                                     "storage" => "configuration",
                                     "restart-required" => "resource-services"

                        BTW, my references to the cache instances are not worked in WF12 anymore and I don't know how to solve them. Should I rename them to the mentioned format or there is another trick?

                        • 9. Re: Wildfly 12 Cache migration error

                          maxoid Correct.  The JNDI names for cache containers, caches, and cache configurations are effectively fixed, using the following patterns:

                          CacheContainer: java:jboss/infinispan/container/<container-name>

                          Cache: java:jboss/infinispan/cache/<container-name>/<cache-name>

                          Cache configuration: java:jboss/infinispan/configuration/<container-name>/<cache-name>


                          Additionally, the default cache of a container and its configuration use the following JNDI name patterns:

                          Default Cache: java:jboss/infinispan/cache/<container-name>/default

                          Default cache configuration: java:jboss/infinispan/configuration/<container-name>/default


                          Anyone needing/wanting to reference these resources using custom names in their code can do so via a resource-ref or resource-env-ref.

                          1 of 1 people found this helpful
                          • 10. Re: Wildfly 12 Cache migration error


                            I have the same problem. I tried to define the resource-ref tag but it didn't worked. How do I define it in an EJB project?

                            • 11. Re: Wildfly 12 Cache migration error

                              gaboros The standard schema for the ejb-jar.xml deployment descriptor contains a resource-ref element.

                              See: http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/ejb-jar_3_2.xsd

                              • 12. Re: Wildfly 12 Cache migration error



                                It worked this way, but it doesn't work with Wildfly-10 now because it's doesn't found the cache config.

                                • 13. Re: Wildfly 12 Cache migration error

                                  gaboros You need to use <lookup-name/> instead of <mapped-name/>.

                                  • 14. Re: Wildfly 12 Cache migration error

                                    Hello pferraro,


                                    with the change from Wildlfy 10 to Wildfly 14, I'm expiriencing the Error, but it presents itself a little different.

                                    public class Foo {
                                        @Resource(lookup = "java:jboss/infinispan/container/Foo")
                                        private CacheContainer container;
                                        private org.infinispan.Cache<String, Integer> cache;
                                        public void initCache() {
                                            this.cache = container.getCache("Bar");

                                    This does throw the following error:

                                    Caused by: org.infinispan.commons.CacheConfigurationException: ISPN000436: Cache 'cacheJOBs' has been requested, but no cache configuration exists with that name and no default cache has been set for this container
                                        at org.infinispan.manager.DefaultCacheManager.wireAndStartCache(DefaultCacheManager.java:602)
                                        at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:589)
                                        at org.infinispan.manager.DefaultCacheManager.internalGetCache(DefaultCacheManager.java:475)
                                        at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:430)
                                        at org.jboss.as.clustering.infinispan.DefaultCacheContainer.getCache(DefaultCacheContainer.java:81)
                                        at com.business.Foo.initCache(Foo.java:22)


                                    So does this mean I need to add the following to the code??

                                    @Resource(lookup = "java:jboss/infinispan/configuration/Foo/Bar")
                                    private Configuration configuration;

                                    If I do so it works without an exception, but confuses me. I would have expected, that getCache would lookup if there is a configuration since in the standalone.xml I do have:

                                    <cache-container name="Foo" default-cache="Bar">
                                        <local-cache name="Bar">
                                            <locking isolation="REPEATABLE_READ"/>


                                    So to me this seems to be a bug in the 9.x Infinispan, since it was working before and I did not find any hint, that this behavior has changed anywhere in the Docs (might be that I oversaw it)

                                    1 2 Previous Next