Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Spring boot Spring Boot-如何为Spring.profiles.active=test禁用@Cacheable?_Spring Boot_Kotlin_Environment Variables_Spring Cache_Spring Profiles - Fatal编程技术网

Spring boot Spring Boot-如何为Spring.profiles.active=test禁用@Cacheable?

Spring boot Spring Boot-如何为Spring.profiles.active=test禁用@Cacheable?,spring-boot,kotlin,environment-variables,spring-cache,spring-profiles,Spring Boot,Kotlin,Environment Variables,Spring Cache,Spring Profiles,我只需要为spring.profiles.active=test的方法启用内存缓存。只需要缓存最近10分钟的请求 现在我这样设置它: @Profile(“测试”) @配置 类CachingConfig{ @豆子 fun cacheManager()=caffee.newBuilder() .expireAfterWrite(10,时间单位:分钟) .build() } @Cacheable(“请求”,key=“#dto.id”) 乐趣请求(dto:RequestDTO):任何{ ... }

我只需要为spring.profiles.active=test的方法启用内存缓存。只需要缓存最近10分钟的请求

现在我这样设置它:

@Profile(“测试”)
@配置
类CachingConfig{
@豆子
fun cacheManager()=caffee.newBuilder()
.expireAfterWrite(10,时间单位:分钟)
.build()
}
@Cacheable(“请求”,key=“#dto.id”)
乐趣请求(dto:RequestDTO):任何{
...
}
@EnableCaching
@SpringBoot应用程序
@EnableConfigurationProperties
班级申请
趣味主线(args:Array){
run(Application::class.java,*args)
}
擦伤

test {
    systemProperty "spring.profiles.active", "test"
}
但我不敢扩展它,因为我不确定它在那里是否能正常工作

我不完全理解:spring.profiles.active=prod如何工作

  • 当没有为其引发cacheManager bean时,是否会出现错误 刺激
  • 在prod spring上,默认情况下是否会提升cacheManager

  • 您需要将
    @EnableCaching
    class Application
    移动到
    class CachingConfig
    ,以使缓存仅对Profile=“test”起作用

    @Profile(“测试”)
    @启用缓存
    @配置
    类CachingConfig{…}
    

    使用这种方法,当非“测试”配置文件处于活动状态时,CachingConfig甚至不会加载到应用程序上下文中

    您需要将
    @EnableCaching
    类应用程序
    移动到
    类CachingConfig
    ,以使缓存仅对Profile=“test”起作用

    @Profile(“测试”)
    @启用缓存
    @配置
    类CachingConfig{…}
    
    使用这种方法,当非“测试”配置文件处于活动状态时,CachingConfig甚至不会加载到应用程序上下文中