springcloud eureka註冊中心搭建
阿新 • • 發佈:2018-11-28
環境描述
① jdk1.8
② idea
③ springcloud版本 Finchley.SR2
④ maven3.0+
匯入jar包
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <addResources>true</addResources> </configuration> </plugin> </plugins> </pluginManagement> </build>
新增配置application.yml
server: port: 8761 spring: application: name: smart-platform-eureka1 eureka: instance: hostname: localhost client: registerWithEureka:false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ server: #eureka服務自我保護模式 預設是開啟的 enable-self-preservation: false #eureka服務 指定時間清理死掉的服務 預設60秒 單位毫秒 eviction-interval-timer-in-ms: 60000
編寫eureka服務啟動類
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer public class Application { public static void main( String[] args) throws Exception{ new SpringApplicationBuilder(Application.class).run(args); } }
效果展示(紅色提示語是因為application.yml配置中將服務自我保護模式設定為了false)