【发布时间】:2019-07-14 10:02:29
【问题描述】:
我正在使用redis缓存和spring boot注解[@Cacheable和@CahePut], 我做了RedisManager transactionAware,它将使用外部事务[缓存层的被调用者]
@Bean
public RedisCacheManager cacheManager() {
RedisCacheManager rcm =
RedisCacheManager.builder(redisConnectionFactory())
.cacheDefaults(cacheConfiguration())
.transactionAware()
.build();
return rcm;
}
在进行如下测试时,我使用的是嵌入式 redis-:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureTestDatabase
@Transactional
public class RoleServiceImplTest extends TestingProfile {
@Before
public void setup() throws Exception {
//setup server and services
redisServer = new RedisServer(redisPort);
redisServer.start();
}
@Test
public void getUsersForRoleForTemplateRole() {
// call to caching layer methods directly annotated with @Cachable
}
...
两次[有和没有@Transactional] spring 无一例外地调用cache.put(key,result),但它只在没有@Transactional 的情况下保留值。
在互联网上找不到太多信息,感谢提前提供任何帮助。
【问题讨论】:
标签: java spring spring-boot caching redis