คำนำ
ยูเรก้าเป็นกรอบการค้นพบและการลงทะเบียน เพื่อให้มีความเฉพาะเจาะจงมากขึ้นเราสามารถแบ่งออกเป็นสองประเภท: Eureka-Server (การค้นพบบริการ) และ Eureka-client (การลงทะเบียนบริการ) เวลานี้เราจะสร้างโครงการสำหรับ Eureka-Server (การค้นพบบริการ) เป็นจุดเริ่มต้นของ Spring-Cloud
ที่อยู่โอเพ่นซอร์ส: https://github.com/bigbeef
โครงสร้างโครงการ
ทุกคนควรรู้โครงสร้างของ Maven (หากคุณไม่ชัดเจนคุณต้องเพิ่มมันมีบทความมากมายเกี่ยวกับ Maven บน Baidu) มาดูการกำหนดค่าไฟล์คีย์เหล่านี้กันเถอะ
การเขียนรหัส
cppba-spring-cloud> pom.xml
<Project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: schemalocation = "http:/MANCMMMMMMMMMMMMMMMMMMMMMMMMMMBM http://maven.apache.org/xsd/maven-4.0.0.xsd "> <moderversion> 4.0.0 </modelversion> <modeversion> <moderversion> <name> $ {project.artifactId} </name> <carent> <menter> <scrientId> org.springframework.boot </groupId> <ratifactid> Spring-Boot-Starter-Parent </artifactid> <cersion> 1.5.5.5 <Project.build.sourceencoding> utf-8 </project.build.sourceencoding> <java.version> 1.8 </java.version> <pring-cloud.ersion> dalston.sr2 </spring-cloud.ersion> <RoupID> org.springframework.cloud </groupId> <ratifactid> Spring-Cloud-Dependencies </artifactid> <persion> $ {Spring-Cloud.version} </sersion> <ply> pom </type> <pope> นำเข้า </scope> <Module> CPPBA-SPRING-Cloud-Eureka-Server </doDule> </ Modules> </project>cppba-spring-cloud-eureka-server> pom.xml
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/ XSI: schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" <cackaging> jar </packaging> <name> $ {project.artifactid} </name> <carent> <scaralId> com.cppba </groupId> <ratifactid> cppba-spring-cloud </artifactid> <cersion> 1.0.0 </เวอร์ชัน> <ArtIfactId> Spring-Cloud-Starter-Eureka-Server </ArtifactId> </การพึ่งพาอาศัย> </การพึ่งพาอาศัย> <uild> <cuildName> $ {Project.Name} </finalname> <plugins> <! <ArtIfactId> Spring-Boot-Maven-Plugin </artifactid> </plugin> </plugins> </ufferspringcloudeurekaserverapplication.java
แพ็คเกจ com.cppba; นำเข้า org.springframework.boot.springapplication; นำเข้า org.springframework.boot.autoconfigure.springbootapplication; นำเข้า org.springframework.cloud.netflix.eureka.server.servere SpringCloudeureKaserverApplication {โมฆะคงที่สาธารณะหลัก (สตริง [] args) {springapplication.run (SpringCloudeUrAserVerapplication.class, args); -Application.properties
server.port = 8761eureka.instance.hostname = eeureka-servereureka.client.registerwitheureka = falseeureka.client.fet chregistry = falseeureka.client.serviceurl.defaultzone = http: // $ {eeureka.instance.hostname}: $ {server.port}/eureka/โครงการเสร็จสมบูรณ์
เริ่มโครงการ
เราเริ่มต้นวิธีการหลักใน SpringCloudeureKaserverApplication และเข้าถึง http://127.0.0.1:8761
ณ จุดนี้โครงการ Eureka-Server (การค้นพบบริการ) ถูกสร้างขึ้นสำเร็จ
ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น