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...
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...
ExtensibleConfigurableCacheFactory.Dependencies deps =
ExtensibleConfigurableCacheFactory factory =
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.