Open Source Project Structure for E-commerce
- Java: 11
- Spring Boot: 2.7.2
- Spring Cloud: 2021.0.3
Eureka: http://localhost:8761/eureka/
Cloud Config: https://github.com/Extremecoder-Group/cloud-config-server
We have to run first "Service-Registry" & then "cloud-config-server" & then Others
We have to add "@LoadBalanced" in the bean declaration. Example:
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
- we have to add service information in the cloud config repository's application.yaml like:
microservice:
product-service:
endpoints:
endpoint:
uri: http://PRODUCT-SERVICE
file-service:
endpoints:
endpoint:
uri: http://FILE-SERVICE
- Need to add the bellows dependencies:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- Need to add the bellow properties in the application yaml:
spring:
application:
name: <SERVICE_NAME>
config:
import: optional:configserver:http://localhost:9900
- Need to add annotation in the Main Application class:
@EnableEurekaClient
- Need to add configuration in "cloud-gateway" application yaml file:
spring
cloud:
gateway:
routes:
- id: file-service
uri: lb://FILE-SERVICE
predicates:
- Path=/file-service/**
- id: product-service
uri: lb://PRODUCT-SERVICE
predicates:
- Path=/product-service/**