搭建单机版Eureka Server
1.使用spring官网生成模板项目,https://start.spring.io/,spring cloud版本Edgware.SR4,spring boot版本1.5.16
2. 修改项目的pom文件
<?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>com.example</groupId> <artifactId>eurekaServer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>eurekaServer</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.16.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Edgware.SR4</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- spring cloud 默认配置启动器 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- spring cloud Eureka Server 启动器 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
3.修改全局配置文件 application.properties
eclipse安装Properties Editor,可以添加中文注释,在Eclipse的 【Help】-> 【 Install New Software.. 】 打开安装插件的向导输入地址,
http://propedit.sourceforge.jp/eclipse/updates/ 稍等片刻,选择Properties Editor安装后重启即可使用。
# 设置spring应用命名,可以自定义,非必要 spring.application.name=eureka-server # 设置Eureka Server WEB控制台端口,自定义 server.port=8761 #是否将自己注册到Eureka-Server中,默认的为true eureka.client.registerWithEureka=false #是否从Eureka-Server中获取服务注册信息,默认为true eureka.client.fetchRegistry=false
4.启动类增加@EnableEurekaServer 注解来开启Eureka Server服务
@EnableEurekaServer @SpringBootApplication public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
5.访问Eureka Server WEB控制台
http://localhost:8761/
解决问题
启动类增加@EnableEurekaServer注解后,提示EnableEurekaServer cannot be resolved to a type,查找网上问题无法解决,遂删除掉maven库中的boot和cloud文件夹,重新更新库问题解决,原因jar包问题