如何通过常规Spring Boot application.properties / application.yml使Ehcache生存时间过期可配置
我当前的应用程序属性:
spring.cache.jcache.config=classpath:ehcache.xml我的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>
主类:
@SpringBootApplication
@EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}有没有办法让这6分钟是可配置的,这样我就可以在运行时/启动时覆盖设置?对于大多数其他Spring Boot集成,会有一些属性允许直接覆盖配置。
发布于 2019-03-04 23:19:31
我认为您可以切换到编程配置,并实现一个新的属性类,就像他们为Jhipster所做的那样:https://www.jhipster.tech/common-application-properties/
有了这个类,它们允许用户在Spring配置中设置TTL,然后您可以自己以编程方式配置缓存管理器:see this example from the ehcache3-samples repo。
Spring / Spring boot使用它们自己的缓存抽象(Spring Cache, fully compliant with the JSR-107 spec),所以我不认为它们的角色是提供与Ehcache3实现的进一步集成;JHipster之类的框架或最终用户都可以。
https://stackoverflow.com/questions/54975613
复制相似问题