【发布时间】:2021-01-09 19:53:13
【问题描述】:
我需要为 spring.profiles.active = test 的方法启用 in_memory 缓存。只需要缓存最近 10 分钟的请求。
现在我这样设置:
@Profile("test")
@Configuration
class CachingConfig {
@Bean
fun cacheManager() = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.build<Any, Any>()
}
@Cacheable("request", key = "#dto.id")
fun request(dto: RequestDTO): Any {
...
}
@EnableCaching
@SpringBootApplication
@EnableConfigurationProperties
class Application
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
build.gragle
test {
systemProperty "spring.profiles.active", "test"
}
但我不敢扩展它,因为我不确定它是否能在那里正常工作。
我不完全明白:这对 spring.profiles.active = prod 有什么作用?
- cacheManager bean 未引发时是否会出错 产品?
- 会不会出现在 prod spring 上默认提升 cacheManager 的情况?
【问题讨论】:
标签: spring-boot kotlin environment-variables spring-cache spring-profiles