3333import org .slf4j .Logger ;
3434import org .slf4j .LoggerFactory ;
3535import org .springframework .beans .factory .annotation .Autowired ;
36+ import org .springframework .beans .factory .annotation .Value ;
37+ import org .springframework .data .redis .core .RedisCallback ;
3638import org .springframework .data .redis .core .RedisTemplate ;
3739import org .springframework .stereotype .Service ;
3840
@@ -45,6 +47,9 @@ public class HealthService {
4547 @ Autowired
4648 private DataSource dataSource ;
4749
50+ @ Value ("${app.version:unknown}" )
51+ private String appVersion ;
52+
4853 @ Autowired (required = false )
4954 private RedisTemplate <String , Object > redisTemplate ;
5055
@@ -78,7 +83,7 @@ public Map<String, Object> checkHealth() {
7883 healthStatus .put ("services" , services );
7984 healthStatus .put ("timestamp" , Instant .now ().toString ());
8085 healthStatus .put ("application" , "admin-api" );
81- healthStatus .put ("version" , "3.1.0" );
86+ healthStatus .put ("version" , appVersion );
8287
8388 logger .info ("Health check completed - Overall status: {}" , overallHealth ? "UP" : "DOWN" );
8489 return healthStatus ;
@@ -138,8 +143,10 @@ private Map<String, Object> checkRedisHealth() {
138143 long startTime = System .currentTimeMillis ();
139144
140145 try {
141- // Test Redis connection with ping
142- String pong = redisTemplate .getConnectionFactory ().getConnection ().ping ();
146+ // Test Redis connection with ping using explicit RedisCallback
147+ String pong = redisTemplate .execute ((RedisCallback <String >) connection -> {
148+ return connection .ping ();
149+ });
143150
144151 if ("PONG" .equals (pong )) {
145152 long responseTime = System .currentTimeMillis () - startTime ;
0 commit comments