1. New Spring Boot Project
2. Add Spring-cloud-starter-eureka-server Dependency (version information required)
<!--https://mvnrepository.com/artifact/org.springframework.cloud/ Spring-cloud-starter-eureka-server- <dependency> <groupId> Org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-eureka-server</ artifactid> <version>1.4. 4. Release</version> </dependency>
3. Setting Program Properties Information
Spring.application.name=myservicehubserver.port=#强制不注册到注册服务器eureka. Client.register -with-eureka=falseEureka.client.fetch-registry=false# Registration Center Address Eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/# Expulsion downline Service, interval, 5 seconds, default is 60, recommended development and test environment configuration # Org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.evictionIntervalTimerInMseureka.server.evictionInt Ervaltimerinms=
4. Create a new. NET core Webapi and install the Pivotal.Discovery.Client NuGet package
Install-package Pivotal.Discovery.Client
public class program { public static void Main (string Span style= "COLOR: #000000" >[] args) {buildwebhost (args). Run (); public static iwebhost buildwebho St (string [] args) => WEBHOST.CREATEDEFAULTB Uilder (args). Usestartup <startup> (). Useurls ( " http://*:5001 " ). Build (); }
Public classStartup { PublicStartup (iconfiguration configuration) {Configuration=configuration; } PublicIConfiguration Configuration {Get; } //This method gets called by the runtime. Use this method to add services to the container. Public voidconfigureservices (iservicecollection services) {services. Adddiscoveryclient (Configuration); Services. Addmvc (); } //This method gets called by the runtime. Use this method to configure the HTTP request pipeline. Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env) {if(env. Isdevelopment ()) {app. Usedeveloperexceptionpage (); } app. Usemvc (); App. Usediscoveryclient (); } }
5.appsettings.json, register service to Eureka-server
{"Logging": { "Includescopes":false, "LogLevel": { "Default":"Warning" }},"Spring": { "Application": { "name":"ServiceOne" }},"Eureka": { "Client": { "serviceurl":"http://localhost:5000/eureka/", "Shouldfetchregistry":false, "Shouldregisterwitheureka":true }, "instance": { "Port":5001 }}}
Spring Cloud +. NET Core implements MicroServices architecture