gpt4 book ai didi

java - Spring Boot 无法设置缓存

转载 作者:行者123 更新时间:2023-12-01 20:05:01 29 4
gpt4 key购买 nike

尝试在Spring Boot项目中设置Memcache,但不起作用。我什至尝试设置默认缓存(ConcurrentMapCacheManager),但它不起作用。

我读过的每个教程(甚至 Spring 官方)都说这个配置足以设置缓存

缓存配置:

@Configuration
@EnableCaching
public class CacheConfiguration {

@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("test_cache");
}

}

缓存使用:

@Service
@CacheConfig(cacheNames = "test_cache")
public class UserServiceImpl extends IUserService {
...
@Cacheable
public UserEntity getByEmail(String email) {
UserEntity entity = repository.findByEmail(email);

return entity;
}
...
}

pom.xml

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.12.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
</dependencies>

是否有可能某些依赖与spring缓存依赖冲突?

最佳答案

如果您使用 Memcached,您的 UserEntity 应该序列化(即UserEntity 实现可序列化)。

您可以查看一个使用 Spring Boot 和 Memcached 的小示例项目 here .

关于java - Spring Boot 无法设置缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47579356/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com