Hello StackOverFlow社区,
我正在使用Spring @Cacheable并在键中添加一个参数,如下所示
@Cacheable(value = "task-status", key = "'get-by-visibility-'+#visible")
@Query(nativeQuery = true, value = "SELECT * FROM prefix_taskstatus WHERE visible=:visible")
public List<TaskStatus> getByVisibility(@Param("visible") Boolean visible);
我创建了一个JUnit测试,如下所示,
@Test
public void test() {
_logger.info(">> test()");
_logger.info(taskStatusRepo.getByVisibility(true).size());
_logger.info(taskStatusRepo.getByVisibility(false).size());
_logger.info(taskStatusRepo.getByVisibility(true).size());
_logger.info(taskStatusRepo.getByVisibility(false).size());
_logger.info("<< test()");
}
JUnit测试的输出如下,
INFO: >> test()
Hibernate:
SELECT * FROM prefix_taskstatus WHERE visible=?
INFO: 10
INFO: 10
INFO: 10
INFO: 10
INFO: << test()
我正在使用下面的
从应用程序上下文文件加载必要的缓存配置@ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring-context/portlet-application-context.xml" })
portlet-application-context.xml具有以下声明
<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="some-name" />
</set>
</property>
</bean>
使用以下注释运行JUnit测试
@RunWith(SpringJUnit4ClassRunner.class)
未从数据库中获取带有“false”的参数。我在这里缺少什么?