Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring Boot使Ehcache TTL超时可配置_Java_Spring_Spring Boot_Ehcache - Fatal编程技术网

Java 使用Spring Boot使Ehcache TTL超时可配置

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 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'>
<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);
  }
}