- 引入客户端依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 配置yml文件
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:50103/eureka/,http://localhost:50102/eureka/
instance:
prefer-ip-address: true
ip-address: localhost
instance-id: demo-web:8080
- 添加注解:@EnableEurekaClient
@SpringBootApplication
@ComponentScan(basePackages = {"com.example"})
@MapperScan(basePackages = {"com.example.mapper"})
@EnableEurekaClient
public class DemoWebApplication {
public static void main(String[] args) {
SpringApplication.run(DemoWebApplication.class, args);
}
}