I have an spring boot application with using hibernate with MySQL as DB.
I'm going to use Redis
for caching, This is my Spring config:
@SpringBootApplication
@EnableAutoConfiguration
@EnableCaching
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(AbcApplication.class, args);
}
}
And my properties file in class path:
spring.cache.type=redis
spring.redis.host=127.0.0.1
spring.redis.port=6379
User model:
@Entity
@Table(name = "USER")
public class User implements Serializable {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...
}
And repository interface:
public interface UserRepository extends JpaRepository<User, Long> {
}
I've put Caching annotation on a controller endpoint:
@GetMapping("/{id}")
@Cacheable(value = "user", key = "#id")
public ResponseEntity getUserDetail(@PathVariable("id") long id) {
User user = userService.getById(id);
return ResponseEntity.ok("user id: " + user.getId());
}
But when i'm invoking this endpoint, this exception thrown:
Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool