pom文件
注意:spring cloud server 使用时需要注意parent的版本号和dependencies的版本号,1.3版本的parent请使用Brixton.SR5
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringCloudServer</groupId>
<artifactId>Spring_Cloud_Server_Two</artifactId>
<version>1.0-SNAPSHOT</version>
<name>springcloudserver_two</name>
<!--spring cloud server 使用时需要注意parent的版本号和dependencies的版本号-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<!--<version>Brixton.SR5</version>-->
<version>Dalston.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
</project>
Application.properties文件
注意:为实现服务的高可用,代码中的注释,还是注释掉的好
spring.application.name=springcloudserver
server.port=9090
eureka.instance.hostname=springcloudserver-first
eureka.client.serviceUrl.defaultZone=http://springcloudserver-two:9091/eureka/
## 不向注册中心注册自己
#eureka.client.register-with-eureka=false
## 设置不去检索服务
#eureka.client.fetch-registry=false
主函数类
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer // eureka注册中心
public class ServerApplication_Two {
public static void main(String[] args) {
new SpringApplicationBuilder(ServerApplication_Two.class).web(true).run(args);
}
}