A Spring Boot application serving as a Service Registry using Consul for microservice discovery and registration. It loads configuration dynamically from environment variables defined in a .env file.
- Loads environment variables with
io.github.cdimascio.dotenv.Dotenv. - Configures Spring Boot application properties dynamically:
- Application name
- Consul host and port for service registry
- Server port for this registry service
- Integrates with Consul for microservices service discovery.
- Java 17+ (compatible with your Spring Boot version)
- Maven for build and run
- A running Consul instance for service registry
.envfile with necessary environment variables
Example .env file:
SPRING_APPLICATION_NAME=service-registry
SPRING_CLOUD_CONSUL_HOST=localhost
SPRING_CLOUD_CONSUL_PORT=8500
SERVER_PORT=8761Adjust these values based on your environment.
Build the project with Maven:
mvn clean installRun the application:
mvn spring-boot:runor
java -jar target/registry-0.0.1-SNAPSHOT.jar