JCache injection null #204
Replies: 1 comment
-
Hello @richmidwinter You need to read Ehcache's official documentation, in order to be able to instantiate the cache. If you currently have no time to do this, then follow this example https://github.com/vladimir-bukhtoyarov/bucket4j/blob/master/bucket4j-jcache/src/test/java/io/github/bucket4j/grid/jcache/ecache/EhcacheCompatibilityInvestigation.java#L19 After playing with cache instantiation register it inside the spring context, for example: @Configuration
public class CacheBeanFactory {
@Bean("buckets")
public Cache<String, byte[]> createCache() {
Cache<String, byte[]> cache = ...;
return cache;
}
} Then inject the cache where you need it, but do not forget to check that object to which dependency needs to be injected is managed by Spring, because annotations like @Autowired, @resource, and @Inject work only for spring beans and do not work for plain objects outside the container. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to follow the examples with JCache integration. The cache defined:
Remains null for me at runtime. How do I configure it?! I'm using spring-boot and have defined in my application.properties:
spring.cache.jcache.config=classpath:ehcache.xml
Beta Was this translation helpful? Give feedback.
All reactions