Spring boot Spring Boot-如何为Spring.profiles.active=test禁用@Cacheable?
我只需要为spring.profiles.active=test的方法启用内存缓存。只需要缓存最近10分钟的请求 现在我这样设置它: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):任何{ ... }
@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如何工作
您需要将
@EnableCaching
从class Application
移动到class CachingConfig
,以使缓存仅对Profile=“test”起作用
@Profile(“测试”)
@启用缓存
@配置
类CachingConfig{…}
使用这种方法,当非“测试”配置文件处于活动状态时,CachingConfig甚至不会加载到应用程序上下文中您需要将
@EnableCaching
从类应用程序
移动到类CachingConfig
,以使缓存仅对Profile=“test”起作用
@Profile(“测试”)
@启用缓存
@配置
类CachingConfig{…}
使用这种方法,当非“测试”配置文件处于活动状态时,CachingConfig甚至不会加载到应用程序上下文中