Opening:
We integrate the previous springboot into the H2 memory database to register the Restful service provided by unit testing and database-independent databases to spring cloud's Eureka Server.
1. Introduce Eureka Client
</dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> </dependency> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
2. Add configuration file
# The application name of the spring boot service registered with Eureka Server spring.application.name=springboot-h2 eureka.instance.prefer-ip-address=true # The address of the Eureka Server registration service is registered with eureka.client.service-url.defaultZone=http://localhost:8761/eureka
3. Turn on Eureka Client support
package com.chhliu.springboot.h2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class SpringbootH2Application { public static void main(String[] args) { SpringApplication.run(SpringbootH2Application.class, args); } }4. Start the spring boot service and verify it
Through the above steps, we have registered the spring boot service to Eureka Server!
5. Possible problems
If during the service registration process, a Connection refused exception is found, as follows:
It is possible that the following mapping relationship is not added to the hosts file
127.0.0.1 loaclhost
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.