Skip to content

Instantly share code, notes, and snippets.

@fb64
Last active March 27, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fb64/0c35271e3a2f023ece33c18bba6223f8 to your computer and use it in GitHub Desktop.
Save fb64/0c35271e3a2f023ece33c18bba6223f8 to your computer and use it in GitHub Desktop.
Workaround to load infinispan config from classthpath with spring-boot jcache configuration.
spring:
cache:
jcache:
config: classpath:config/cache/infinispan.xml
import org.infinispan.configuration.parsing.ParserRegistry
import org.infinispan.jcache.embedded.JCacheManager
import org.infinispan.manager.DefaultCacheManager
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.cache.CacheProperties
import org.springframework.cache.annotation.EnableCaching
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.net.URI
import javax.cache.CacheManager
import javax.cache.Caching
@Configuration
@EnableCaching
class CacheConfiguration {
@Autowired
@Bean
fun getCacheManager(cacheProperties: CacheProperties): CacheManager {
val configHolder= ParserRegistry().parse(cacheProperties.jcache.config.inputStream)
val cacheManager = DefaultCacheManager(configHolder,true)
return JCacheManager(URI.create(cacheManager.name), cacheManager, Caching.getCachingProvider())
}
}
<?xml version="1.0" encoding="utf-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:9.2 http://www.infinispan.org/schemas/infinispan-config-9.2.xsd"
xmlns="urn:infinispan:config:9.2">
<cache-container default-cache="replicatedCache" name="mycache-container">
<transport cluster="my-cluster"/>
<replicated-cache name="replicatedCache"/>
</cache-container>
</infinispan>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment