Spring Boot简单缓存导致404错误

时间:2017-12-09 14:45:50

标签: java spring caching spring-cache

我正在尝试将Spring缓存添加到我的项目中。我在网上阅读了getting started和一些示例,看起来很简单,但是当我使用可缓存注释时,我的方法会导致 HTTP 404 错误。

这些是我的步骤:

将缓存依赖项添加到我的pom.xml

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>

@EnableCaching注释添加到我的主类。

@SpringBootApplication
@EnableCaching
public class MyProjectApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyProjectApplication.class, args);
    }

}

将CacheManager Bean添加到我的项目中:

@Configuration
public class ConfigApplication {

    @Bean
    public CacheManager cacheManager() {
        String[] cacheNames = { "videoInfo" };
        return new ConcurrentMapCacheManager(cacheNames);
    }
}

现在,在我喜欢缓存的方法中,我添加了@Cacheable("videoInfo")注释。 (此方法的bean使用@RestController注释)。我在@CacheEvict添加了其他方法来重置缓存。

@Override
@Cacheable("videoInfo")
@RequestMapping(value = "/get-video-download", method = RequestMethod.POST, produces = "application/json")
public DownloadInfo getDownloadUrls(@RequestParam String videoId) {
    DownloadInfo di = null;
    di = downloadService.getDownloadInfo(videoId);
    return di;
}

@CacheEvict(value = "videoInfo", allEntries = true)
@RequestMapping(value = "/get-video-download-reset-cache", method = RequestMethod.GET)
public void getDownloadUrlsResetCache() {
    LOG.debug("Se ha limpiado la caché de videos correctamente");
}

然后,当我对此bean中的任何方法发出HTTP请求时,出现404错误。如果我在上述方法中评论这两个注释,我就不会看到错误的日志,并且一切正常。对此有何想法?

0 个答案:

没有答案