上一篇我們回顧了關(guān)于 spring cloud eureka的相關(guān)基礎(chǔ)知識,現(xiàn)在我們針對于HongHu cloud的eureka項(xiàng)目做以下構(gòu)建碟渺,整個(gè)構(gòu)建的過程很簡單,我會(huì)將每一步都構(gòu)建過程記錄下來谋国,希望可以幫助到大家:
- 創(chuàng)建一個(gè)名為particle-common-eureka的maven項(xiàng)目埋涧,繼承particle-commonservice,具體的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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ml.honghu</groupId>
<artifactId>particle-commonservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>particle-commonservice-eureka</artifactId>
<packaging>jar</packaging>
<name>particle-commonservice-eureka</name>
<description>particle-commonservice project for Spring Boot</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>2</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
- 在啟動(dòng)類入口引用eureka的相關(guān)配置巷挥,代碼如下:
package com.ml.honghu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class ServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
}
- 配置application.yml文件
# server (eureka 默認(rèn)端口為:8761)
server:
port: 8761
# spring
spring:
application:
name: particle-commonservice-erueke
# eureka
eureka:
client:
# 是否注冊到eureka
register-with-eureka: true
# 是否從eureka獲取注冊信息
fetch-registry: false
availability-zones:
honghu: honghuZone
service-url:
honghuZone: http://honghu:123456@localhost:8761/eureka/
defaultZone: http://honghu:123456@localhost:8761/eureka/
instance:
prefer-ip-address: true
hostname: localhost
metadataMap:
zone: honghuZone
user: ${security.user.name}
password: {security.user.password}
# 指定環(huán)境
environment: dev
#指定數(shù)據(jù)中心
datacenter: honghu
# 關(guān)閉自我保護(hù)模式
server:
enable-self-preservation: false
#設(shè)置清理無效節(jié)點(diǎn)的時(shí)間間隔桩卵,默認(rèn)60000,即是60s
eviction-interval-timer-in-ms: 60000
# 服務(wù)認(rèn)證
security:
basic:
enabled: true
user:
name: honghu
password: 123456
management:
security:
enabled: false
4. 增加項(xiàng)目的log機(jī)制和打包運(yùn)行機(jī)制(后面我們會(huì)詳細(xì)編寫針對于Linux Centos下的打包部署機(jī)制)
5. 自此整個(gè)項(xiàng)目部署完成倍宾,通過手動(dòng)方式進(jìn)行Run As --> Spring Boot App,運(yùn)行結(jié)果如下:
控制臺運(yùn)行結(jié)果:
訪問控制臺并登陸:
控制臺運(yùn)行效果:
從現(xiàn)在開始雏节,我這邊會(huì)將近期研發(fā)的spring cloud微服務(wù)云架構(gòu)的搭建過程和精髓記錄下來,幫助更多有興趣研發(fā)spring cloud框架的朋友高职,大家來一起探討spring cloud架構(gòu)的搭建過程及如何運(yùn)用于企業(yè)項(xiàng)目钩乍。完整項(xiàng)目的源碼來源 技術(shù)支持1791743380。