1.pom.xml
<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>com.hive</groupId>
<artifactId>user-eureka</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging><name>eureka_user</name>
<url>http://maven.apache.org</url><parent>
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId><!--配合spring cloud版本--> <version>1.4.3.RELEASE</version> </parent><!--设置字符编码及java版本-->
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version>
</properties> <dependencies><!--增加eureka-server的依赖-->
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies><!--依赖管理,用于管理spring-cloud的依赖-->
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <!--使用该插件打包--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>2.application
package com.hivescm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication//springBoot注解,spring在springBoot基础之上来构建项目
@EnableEurekaServer//开启eureka服务public class EurekaApplication { public static void main(String[] args) {//spirng boot的标准入口
SpringApplication.run(EurekaApplication.class, args); }}3.application.yml
server:
port: 8761#指定服务端口eureka: client: register-with-eureka: false #是否将eureka自身作为应用注册到eureka注册中心 fetch-registry: false #为true时,可以启动,但报异常:Cannot execute request on any known server service-url: defaultZone: http://192.168.106.49:8761/eureka
简单的eureka就写好了,运行下EurekaApplication .java
访问: