Java 使用Spring Boot使Ehcache TTL超时可配置
如何通过常规的Spring Boot application.properties/application.yml配置Ehcache生存时间到期 我当前的应用程序属性:Java 使用Spring Boot使Ehcache TTL超时可配置,java,spring,spring-boot,ehcache,Java,Spring,Spring Boot,Ehcache,如何通过常规的Spring Boot application.properties/application.yml配置Ehcache生存时间到期 我当前的应用程序属性: spring.cache.jcache.config=classpath:ehcache.xml My ehcache.xml: <config xmlns:jsr107='http://www.ehcache.org/v3/jsr107' xmlns='http://www.ehcache.org/v3'> &l
spring.cache.jcache.config=classpath:ehcache.xml
My ehcache.xml:
<config xmlns:jsr107='http://www.ehcache.org/v3/jsr107' xmlns='http://www.ehcache.org/v3'>
<service>
<jsr107:defaults enable-management="true" enable-statistics="true"/>
</service>
<cache alias="Ttl" uses-template="ttl-template"/>
<cache-template name="ttl-template">
<expiry>
<ttl unit="minutes">6</ttl>
</expiry>
<resources>
<heap>10000</heap>
</resources>
</cache-template>
有没有办法使这6分钟可配置,以便我可以在运行时/启动时覆盖设置?对于大多数其他Spring Boot集成,会有一些属性允许直接覆盖配置。我认为您可以切换到编程配置,并实现一个新的属性类,就像他们为Jhipster所做的那样: 使用这个类,它们允许用户在Spring配置中设置TTL,然后您可以自己以编程方式配置缓存管理器
Spring/Spring引导使用他们自己的缓存抽象,所以我认为他们的角色不是提供与Ehcache3实现的进一步集成;不过,JHipster之类的框架或最终用户都可以。这可能可行,但看起来并不直观。谢谢
@SpringBootApplication
@EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}