Reputation: 1
So, I'm simply trying to set up a Config Client that is supposed to fetch 2 simple config values from a Config Service that is connected to my git repo. As I've stated in the title, it seems the client is not connecting to the config service.
I'll print here the follwing:
it is private but pasted it here so you can see it in configuration it contains a text file called 'resource-service.yml' which only contains: user: firstName: Sebastian lastName: Mocanu
2.Config Service
@SpringBootApplication
@EnableConfigServer
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
application.yml
server:
port: 8888
servlet:
context-path: /config-service
spring:
application:
name: config-service
cloud:
config:
server:
git:
uri: [email protected]:SebastianMocanu/LearningSpace.git
clone-on-start: true
default-label: master
security:
user:
name: AAAA
password: BBBB
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
controller - supposed to fetch user.firstName and user.lastName from config service
@RestController
@Slf4j
public class ResourceController {
@Autowired
private ConfigProperties configProperties;
@GetMapping("/getResource")
private String getResource() {
log.info("API successfully called at " + LocalDateTime.now());
String message = String.format("Here is your resource Mr. %1$s %2$s ! :D",
configProperties.getConfigValue("user.firstName"),
configProperties.getConfigValue("user.lastName"));
return message;
}
}
application.yml
spring:
application:
name: resource-service
profiles:
active: development
cloud:
config:
uri: http://localhost:8888
username: AAAA
password: BBBB
name: config-service
fail-fast: true
enabled: false
bootstrap:
enabled: true
server:
port: 8080
servlet:
context-path: /resource-service
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
management:
endpoints:
web:
exposure:
include: env
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
</dependencies>
I've read documentation, followed blogs, consulted ChatGPT and it seems I have all it takes: dependencies done right, annotations just fine, configuration on both sides clean. I've checked if the config service is connected to the git repo and it seems just fine tho.
Worst part is I'm not getting any error. When I call the API in the client (resource-service) I get null for both values:
OUTPUT: Here is your resource Mr. null null ! :D
I also tried adding bootstrap file and its dependency and config vars in app.yml but not luck. Im out of ideas. Please help!
Upvotes: 0
Views: 40