79782332

Date: 2025-10-04 06:33:31
Score: 0.5
Natty:
Report link

THIS IS NOT AN ANSWER, JUST GATHERING DEBUG INFORMATION.

ADD ProfileController.java into your Spring Boot backend project.

ProfileController.java

package com.example;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;

@RestController
public class ProfileController {
    private static final Logger logger = LoggerFactory.getLogger(ProfileController.class);

    private final Environment env;

    @Value("${message}")
    private String message;

    @Value("${spring.redis.host}")
    private String redisHost;
    
    @Value("${spring.redis.port}")
    private String redisPort;
    
    @Value("${spring.redis.timeout}")
    private String redisTimeout;

    public ProfileController(Environment env) {
        this.env = env;
    }

    @GetMapping("/infoJson")
    public Map<String, String> getInfoJson() {
        String[] profiles = env.getActiveProfiles();
        String profile = profiles.length > 0 ? profiles[0] : "default";
        logger.info("Current Profile: {} , Message: {}" , profile, message);

        Map<String, String> result = new HashMap<>();
        result.put("profile", profile);
        result.put("message", message);
        result.put("spring.redis.host", redisHost);
        result.put("spring.redis.port", redisPort);
        result.put("spring.redis.timeout", redisTimeout);
        
        logger.info("Result: {}", result); 
        
        return result;
    }
}

application-docker.properties

ADD message , message=DOCKER Hello from properties!

spring.application.name=demo-redis-docker
message=DOCKER Hello from properties!

spring.redis.host=${SPRING_DATA_REDIS_HOST}
spring.redis.port=${SPRING_DATA_REDIS_PORT}
spring.redis.timeout=10000ms

*Note: I changed the configuration property name to use spring.redis.host instead of spring.data.redis.host because I am using Spring Boot 3.x.

In the host:

open CMD.exe . run command curl http://localhost:8080/infoJson

Result:

curl http://localhost:8080/infoJson
{"spring.redis.host":"app-redis","profile":"docker","spring.redis.port":"6379","spring.redis.timeout":"10000ms","message":"DOCKER Hello from properties!"}

Use ProfileController.java (http://localhost:8080/infoJson) to display which profile you are currently using and the value of the setting (spring.redis.host).

You should first verify the information: why does your error message show a connection to localhost/127.0.0.1 (connection refused: no further information: localhost/127.0.0.1:6379)?

Reasons:
  • Blacklisted phrase (1): NOT AN ANSWER
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: life888888