首先新建一个maven项目springcloud


再分别建子项目Module Spring Initializr建项目


分别建config-server ,eurake-client ,eurakeserver 项目


1.关于eurake-client的application.yml的配置


service-url:

defaultZone: http://localhost:8888/eureka/

server:

port: 9999

spring:

application:

name: eurake-client

1.关于eurake-client的EurakeClientApplication的写法


package com.example.eurakeclient;


import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


@SpringBootApplication

@EnableEurekaClient

@RestController

public class EurakeClientApplication {


public static void main(String[] args) {

SpringApplication.run(EurakeClientApplication.class, args);

}

@Value("${server.port}")

String port;

@RequestMapping("/")

public String home(){

return "hello world from port"+port;

}

}

二:eurakeserver


1.application.yml的配置


server:

port: 8080


eureka:

instance:

hostname: localhost

client:

register-with-eureka: false

fetch-registry: false

service-url:

defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

2.EurakeserverApplication的写法


package com.example.eurakeserver;


import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication

public class EurakeserverApplication {


public static void main(String[] args) {

SpringApplication.run(EurakeserverApplication.class, args);

}

}

三:启动EurakeClientApplication


"C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\bin\java" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=49789 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Java\Java Unitl\LRX\IntelliJ IDEA 2017.2.6\lib\idea_rt.jar=49790:C:\Java\Java Unitl\LRX\IntelliJ IDEA 2017.2.6\bin" -Dfile.encoding=UTF-8 -classpath "C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\charsets.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\deploy.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\javaws.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\jce.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\jfr.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\jsse.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\management-agent.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\plugin.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\resources.jar;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\jre\lib\rt.jar;D:\co\springclouds\eurake-client\target\classes;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-starter\2.0.4.RELEASE\spring-boot-starter-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot\2.0.4.RELEASE\spring-boot-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\spring-context\5.0.8.RELEASE\spring-context-5.0.8.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.0.4.RELEASE\spring-boot-autoconfigure-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.0.4.RELEASE\spring-boot-starter-logging-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\13485\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\13485\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;C:\Users\13485\.m2\repository\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;C:\Users\13485\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\13485\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\13485\.m2\repository\org\springframework\spring-core\5.0.8.RELEASE\spring-core-5.0.8.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\spring-jcl\5.0.8.RELEASE\spring-jcl-5.0.8.RELEASE.jar;C:\Users\13485\.m2\repository\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;C:\Users\13485\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\13485\.m2\repository\org\springframework\cloud\spring-cloud-netflix-eureka-client\2.0.0.RELEASE\spring-cloud-netflix-eureka-client-2.0.0.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\cloud\spring-cloud-netflix-core\2.0.0.RELEASE\spring-cloud-netflix-core-2.0.0.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.0.4.RELEASE\spring-boot-starter-aop-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\org\aspectj\aspectjweaver\1.8.13\aspectjweaver-1.8.13.jar;C:\Users\13485\.m2\repository\org\springframework\spring-web\5.0.7.RELEASE\spring-web-5.0.7.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\spring-beans\5.0.8.RELEASE\spring-beans-5.0.8.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.0.4.RELEASE\spring-boot-starter-web-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.0.4.RELEASE\spring-boot-starter-json-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;C:\Users\13485\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\13485\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;C:\Users\13485\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.6\jackson-datatype-jdk8-2.9.6.jar;C:\Users\13485\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.6\jackson-datatype-jsr310-2.9.6.jar;C:\Users\13485\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.6\jackson-module-parameter-names-2.9.6.jar;C:\Users\13485\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.0.4.RELEASE\spring-boot-starter-tomcat-2.0.4.RELEASE.jar;C:\Users\13485\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.32\tomcat-embed-core-8.5.32.jar;C:\Users\13485\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.32\tomcat-embed-el-8.5.32.jar;C:\Users\13485\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.32\tomcat-embed-websocket-8.5.32.jar;C:\Users\13485\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.11.Final\hibernate-validator-6.0.11.Final.jar;C:\Users\13485\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\13485\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\13485\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\13485\.m2\repository\org\springframework\spring-webmvc\5.0.8.RELEASE\spring-webmvc-5.0.8.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\spring-aop\5.0.8.RELEASE\spring-aop-5.0.8.RELEASE.jar;C:\Users\13485\.m2\repository\org\springframework\spring-expression\5.0.8.RELEASE\spring-expression-5.0.8.RELEASE.jar" com.example.eurakeclient.EurakeClientApplication


. ____ _ __ _ _

/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \

( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

\\/ ___)| |_)| | | | | || (_| | ) ) ) )

' |____| .__|_| |_|_| |_\__, | / / / /

=========|_|==============|___/=/_/_/_/

:: Spring Boot :: (v2.0.4.RELEASE)


2018-08-25 10:48:14.169 INFO 6048 --- [ main] c.e.e.EurakeClientApplication : Starting EurakeClientApplication on DESKTOP-ABNUP0Q with PID 6048 (D:\co\springclouds\eurake-client\target\classes started by BODI2018 in D:\co\springclouds)

2018-08-25 10:48:14.171 INFO 6048 --- [ main] c.e.e.EurakeClientApplication : No active profile set, falling back to default profiles: default

2018-08-25 10:48:14.227 INFO 6048 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@76508ed1: startup date [Sat Aug 25 10:48:14 CST 2018]; root of context hierarchy

2018-08-25 10:48:16.719 INFO 6048 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9999 (http)

2018-08-25 10:48:16.750 INFO 6048 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]

2018-08-25 10:48:16.750 INFO 6048 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.32

2018-08-25 10:48:16.765 INFO 6048 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\bin;C:\Java\Java Unitl\LRX\mysql-5.6.40-winx64\mysql-5.6.40-winx64\bin;C:\Program Files\nodejs\;C:\Users\13485\Downloads\node-v8.11.3-win-x64.zip\node-v8.11.3-win-x64\node_modules\npm;C:\WINDOWS\System32\OpenSSH\;C:\Users\13485\AppData\Local\Microsoft\WindowsApps;C:\Java\Java Unitl\LRX\Java\jdk1.8.0_111\bin;C:\Users\13485\AppData\Roaming\npm;;.]

2018-08-25 10:48:16.928 INFO 6048 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext

2018-08-25 10:48:16.928 INFO 6048 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2703 ms

2018-08-25 10:48:17.006 INFO 6048 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]

2018-08-25 10:48:17.006 INFO 6048 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]

2018-08-25 10:48:17.006 INFO 6048 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

2018-08-25 10:48:17.006 INFO 6048 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]

2018-08-25 10:48:17.006 INFO 6048 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]

2018-08-25 10:48:17.162 INFO 6048 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

2018-08-25 10:48:17.303 INFO 6048 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@76508ed1: startup date [Sat Aug 25 10:48:14 CST 2018]; root of context hierarchy

2018-08-25 10:48:17.334 INFO 6048 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.example.eurakeclient.EurakeClientApplication.home()

2018-08-25 10:48:17.334 INFO 6048 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)

2018-08-25 10:48:17.334 INFO 6048 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

2018-08-25 10:48:17.349 INFO 6048 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

2018-08-25 10:48:17.349 INFO 6048 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

2018-08-25 10:48:17.443 INFO 6048 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup

2018-08-25 10:48:17.521 INFO 6048 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9999 (http) with context path ''

2018-08-25 10:48:17.521 INFO 6048 --- [ main] c.e.e.EurakeClientApplication : Started EurakeClientApplication in 4.202 seconds (JVM running for 5.487)



四:访问


http://localhost:9999/


成功