Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

It's been a while since I dipped my feet into Oracle Coherence but I figured that I'd revisit the topic again. In 2018 after upgrading to WebLogic 12.2, I started to experience some class loader issues, this unfortunately impacted how my web services were loading Coherence configuration. It turned out that the tangosol-coherence-override.xml file wasn't being loaded from the WEB-INF/classes directory and I needed a different solution.

After some initial tinkering, everything worked fine when I had a single web service deployed, but when I tried to deploy multiple services that used Coherence, the following exception would get thrown during service startup...
 Error
java.lang.IllegalStateException: Service "ReplicatedCache" has been started by a different configurable cache factory.


Ugh! Maybe I needed to look at my class loader configuration in better detail, but I felt like there should be a very simple solution for this.

This article was a great help, but it wasn't the final solution. I didn't want to specify the entire Coherence cache configuration programatically but I did want to control which configuration file was loaded by Coherence using code in my web service's PostConstruct annotated method.

Discussing the issue with a Coherence engineer, this is something I ended up coming up with...
 Java
ExtensibleConfigurableCacheFactory.Dependencies deps =
ExtensibleConfigurableCacheFactory.DependenciesHelper.newInstance("my-coherence-cache-config.xml");
ExtensibleConfigurableCacheFactory factory =
new ExtensibleConfigurableCacheFactory(deps);
ClassLoader loader = this.getClass().getClassLoader();
NamedCache nc = factory.ensureCache("MY_CACHE", loader);


The key was the ExtensibleConfigurableCacheFactory.DependenciesHelper class. The file, my-coherence-cache-config.xml, was bundled with my web service (WEB-INF/classes) and contained all the Coherence cache configuration that was needed for a specific web service. Now different web services could load their own configurations! The main down-side was that I needed to keep track of the factory class.

In the end I didn't use this approach and opted for an even simpler solution, which I'll discuss in another article. Update: the simpler solution blog post is here - Easiest way to specify custom Coherence cache configuration with WebLogic 12c.



-i

Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...