当spring.factories文件中没有JCache配置文件条目时,Spring Boot如何自动配置JCache?

时间:2017-06-09 10:49:31

标签: spring spring-boot ehcache jcache

我是春季启动项目的新手。 目前我正在开发一个带有spring boot的项目,带有ehcache实现的Jcache。

我试图了解spring boot如何自动配置Cache Framework。我做了自己的研究并确定了Spring引导@EnableAutoConfiguration读取spring.factories文件,并根据类路径中可用的类自动配置Cache相关的bean。

这是Spring引导缓存自动配置基于Java的配置文件,可在spring.factories文件

下找到

org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\

但是对于Jcache,“JCacheCacheConfiguration.java”是Spring Boot自动配置文件,但是此文件在autoconfigurer.jar文件中的spring.factroies文件下不可用。

那么Spring boot如何自动配置Jcache而不在spring.factories文件中输入?

1 个答案:

答案 0 :(得分:2)

JCache实现正在提供服务(在$.ajax({ url: 'data.json', dataType: 'json', success: function( data ) { console.log( "SUCCESS: " ); console.log( data ); }, error: function(data, textStatus, errorThrown) { console.log("textStatus: ",textStatus); console.log("errorThrown: ",errorThrown); } }); 中)。所以Spring可以神奇地找到实现。更简单的是META-INF,它将找到提供者并立即为您提供缓存。

然后,您将需要提供特定的缓存配置。最简单的方法是在@EnableCaching中指定spring.cache.jcache.config=ehcache.xml

就是这样。您将在ehcache samplepet clinic中找到更复杂的Java(无xml)配置。