各个章节可能有关联关系,查找《SpringCloud实战教程》其他章节请参考:
http://www.yayihouse.com/yayishuwu/book/79
2. Idea创建springcloud服务发现及注册中心服务端eurekaServer工程
(1) 右键刚刚创建好的工程--》New--》Module--》Spring Initializr--》next--》修改一下Group为com.wlg.springcloud和Artifact为eureka-server--》next--》Spring Cloud Discovey--》勾选Euraka Server --》 next--》Finish。
(2) 在启动类上加上@EurekaServerApplication注解
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
(3) 把application.properties改为application.yml,内容如下:
server:
port: 9901
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
(4) 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>com.wlg.springcloud</groupId>
      <artifactId>springcloud</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </parent>
   <groupId>com.wlg.springcloud</groupId>
   <artifactId>eureka-server</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>eureka-server</name>
   <description>Demo project for Spring Boot</description>
   <properties>
      <java.version>1.8</java.version>
   </properties>
   <dependencies>
      <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      </dependency>
   </dependencies>
</project>
(5) 启动注册中心服务端
右键启动类EurekaServerApplication,选择“Run EurekaServerApplication”或者选择“Debug EurekaServerApplication”启动注册中心服务端
(6) 浏览器访问:http://localhost:9901/就可以看到eureka信息
