Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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 在运行时修改Ehcache配置_Java_Spring_Ehcache_Terracotta - Fatal编程技术网

Java 在运行时修改Ehcache配置

Java 在运行时修改Ehcache配置,java,spring,ehcache,terracotta,Java,Spring,Ehcache,Terracotta,我正在Spring框架中使用ehcache。我正在使用ehcache.xml初始化ehcache。但是,我想在运行时添加某些属性,例如terracottaconfig。为此,我重写了类EhCacheManagerFactoryBean。目前,我正在重写该类的方法getObject()(我不知道这是否是要重写的正确方法,因为在使用ehcache.xml文件初始化该类之前调用了其他方法setResource()和afterPropertieSet() 这是我的spring配置文件 <bean

我正在Spring框架中使用ehcache。我正在使用ehcache.xml初始化ehcache。但是,我想在运行时添加某些属性,例如terracottaconfig。为此,我重写了类EhCacheManagerFactoryBean。目前,我正在重写该类的方法getObject()(我不知道这是否是要重写的正确方法,因为在使用ehcache.xml文件初始化该类之前调用了其他方法setResource()和afterPropertieSet()

这是我的spring配置文件

<bean id="cacheManager"
class="com.dexknows.util.CustomEhCacheManagerFactoryBean">
<property name="configLocation">
   <value>file:///${vp_data_dir}/ehcache.xml</value>
</property>     
<property name="terracottaConfigUrl" value="#{dexProperties['terracottaConfig.Url']}"/>
</bean>
我得到以下例外情况:

创建名为“cacheManager”的bean时出错:FactoryBean在创建对象时引发异常;嵌套异常为java.lang.IllegalStateException:net.sf.ehcache.config.Configuration.dynamicConfig无法动态更改

我已设置dynamicConfig=“true”



在分析EhCacheManagerFactoryBean类的源代码后,我发现“terracottaConfigConfiguration”无法动态更改只能动态更改枚举DynamicProperty中提到的属性。尽管如此,如果有人找到了文档,提到了同样的内容,这将是很有帮助的。

在分析了EhCacheManagerFactoryBean类的源代码后,我发现“terracottaConfigConfiguration”不能动态更改只能动态更改枚举DynamicProperty中提到的属性。尽管如此,如果有人找到了文档,提到了相同的内容,这将非常有用。

只有几个动态属性:

  • timeToIdleSeconds
  • timeToLiveSeconds
  • maxElementsInMemory
  • maxElementsOnDisk

官方(“动态配置”)中提到了它们。

只有几个动态属性:

  • timeToIdleSeconds
  • timeToLiveSeconds
  • maxElementsInMemory
  • maxElementsOnDisk
官方文件(“动态配置”)中提到了它们

public class CustomEhCacheManagerFactoryBean extends EhCacheManagerFactoryBean {

    private String terracottaConfigUrl;
    private Resource resourceConfiguration;

    @Override
    public void setConfigLocation(Resource configLocation) {            
        super.setConfigLocation(configLocation);
    }

    @Override
    public void afterPropertiesSet() throws IOException, CacheException {

        super.afterPropertiesSet();
    }


    @Override
    public CacheManager getObject() {

        CacheManager manager = super.getObject();

        TerracottaClientConfiguration terracottaClientConfiguration = new TerracottaClientConfiguration();
        terracottaClientConfiguration.setRejoin(true);
        terracottaClientConfiguration.setUrl(terracottaConfigUrl);



        manager.getConfiguration().setDynamicConfig(true);
        manager.getConfiguration().terracotta(terracottaClientConfiguration);

Configuration().terracotta(terracottaClientConfiguration)));
    return manager;

    }

    public String getTerracottaConfigUrl() {
        return terracottaConfigUrl;
    }

    public void setTerracottaConfigUrl(String terracottaConfigUrl) {
        this.terracottaConfigUrl = terracottaConfigUrl;
    }

}
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
         updateCheck="false"
         monitoring="autodetect"
         dynamicConfig="true"
         name="xyz">