项目地址
springcloud 注册中心(eureka)搭建
- 在spring-cloud项目中新建register-server (maven)模块
- pom.xml 引入开发包及插件
<?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">
<parent>
<artifactId>spring-cloud</artifactId>
<groupId>spring-cloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>register-server</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- maven打包插件 能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Maven操作的可能 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- java目录下创建路径(com.springcloud.demo)及启动类 RegisterServerApplication.java
package com.springcloud.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* 开发公司:青岛海豚数据技术有限公司
* 版权:青岛海豚数据技术有限公司
* <p>
* RegisterServerApplication
*
* @author 刘志强
* @created Create Time: 2019/3/26
*/
@SpringBootApplication
@EnableEurekaServer // 启动注册中心服务注解
public class RegisterServerApplication implements CommandLineRunner {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public static void main(String[] args) {
SpringApplication.run(RegisterServerApplication.class, args);
}
@Override
public void run(String... strings) throws Exception {
logger.info("服务器启动成功");
}
}
- 创建配置文件application.yml
server:
port: 5000 # 注册中心占用6000端口
spring:
application:
name: register-server
eureka:
instance:
hostname: 127.0.0.1
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
4 运行 RegisterServerApplication 访问 http://localhost:5000/