Spring boot @SpringBootTest尝试连接到实际的Ehcache实例

Spring boot @SpringBootTest尝试连接到实际的Ehcache实例,spring-boot,ehcache,spring-test,terracotta,Spring Boot,Ehcache,Spring Test,Terracotta,我们的Spring Boot应用程序应该能够从远程Ehcache实例获取数据。为此,添加了以下配置 @配置 @启用缓存 公共类缓存管理器{ 私有静态最终字符串TERRACOTTA_LINK=“TERRACOTTA://”; 私有最终EhcacheConfiguration EhcacheConfiguration; 公共EhcacheManager(EhcacheConfiguration EhcacheConfiguration){ this.ehcacheConfiguration=ehca

我们的Spring Boot应用程序应该能够从远程Ehcache实例获取数据。为此,添加了以下配置

@配置
@启用缓存
公共类缓存管理器{
私有静态最终字符串TERRACOTTA_LINK=“TERRACOTTA://”;
私有最终EhcacheConfiguration EhcacheConfiguration;
公共EhcacheManager(EhcacheConfiguration EhcacheConfiguration){
this.ehcacheConfiguration=ehcacheConfiguration;
}
@豆子
PersistentCacheManager PersistentCacheManager(){
返回ehCacheManager();
}
私有PersistentCacheManager ehCacheManager(){
最后一个字符串ehcacheURI=TERRACOTTA_LINK+ehcacheConfiguration.getHost()+“:“+ehcacheConfiguration.getPort()+”/“+ehcacheConfiguration.getResource();
PersistentCacheManager cacheManager=newCacheManagerBuilder()
.with(cluster(create(ehcacheURI)).autoCreate())
.构建(真实);
CacheConfigurationMyCache=newCacheConfigurationBuilder(String.class,String.class,
newResourcePoolsBuilder()
.具有服务(具有一致性(最终))
.withDefaultResilienceStrategy()
.build();
createCache(“someCacheKey”,myCache);
返回缓存管理器;
}
}
但是,我们所有的集成测试都有一个问题,这些测试都用
@SpringBootTest
注释。这些测试将加速应用程序上下文,并以此尝试连接到远程Ehcache实例;这是免费的


有没有办法禁用此实例化?或者我需要为集成测试启动嵌入式Ehcache服务器之类的东西来启动应用程序上下文吗?

如果您的应用程序可以在禁用Ehcache的情况下运行,您只需编辑
@springbootest
注释即可禁用Ehcache,例如:
@springbootest(属性={“property.to.disable.ehcache=true”})
,保证仅在测试阶段禁用ehcache


如果您的应用程序要求启用EhCache,最好添加一个
src/test/resources/application.properties
文件,其中包含指向本地(可能是嵌入测试的)EhCache实例的属性(如主机、端口等)