SpringCloud微服务实战:一、Eureka注册中心服务…

2019-02-17 01:50:22来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

1.项目启动类application.java类名上增加@EnableEurekaServer注解,声明是注册中心
 1 import org.springframework.boot.SpringApplication;
 2 import org.springframework.boot.autoconfigure.SpringBootApplication;
 3 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
 4 @SpringBootApplication
 5 @EnableEurekaServer
 6 public class EurekaApplication {
 7  public static void main(String[] args) {
 8  SpringApplication.run(EurekaApplication.class, args);
 9  }
10 }
2.application.yml配置:
 1 #配置注册中心服务端信息
 2  eureka:
 3  client:
 4  service-url:
 5  defaultZone: http://localhost:8762/eureka/
 6  #配置是否显示在注册中心上
 7  register-with-eureka: false
 8  #自我保护机制,开发环境可以关闭,生产环境必须开启
 9  server:
10  enable-self-preservation: false
11  #配置在注册中心显示的名字
12  spring:
13  application:
14  name: eureka
15  #配置服务端口
16  #server:
17  #  port: 8761
3.pom.xml配置:
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4  <modelVersion>4.0.0</modelVersion>
 5 
 6  <groupId>com.kjm</groupId>
 7  <artifactId>eureka</artifactId>
 8  <version>0.0.1-SNAPSHOT</version>
 9  <packaging>jar</packaging>
10 
11  <name>eureka</name>
12  <description>Eureka服务端</description>
13 
14  <parent>
15  <groupId>org.springframework.boot</groupId>
16  <artifactId>spring-boot-starter-parent</artifactId>
17  <version>2.1.0.RELEASE</version>
18  <relativePath/> <!-- lookup parent from repository -->
19  </parent>
20  <properties>
21  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23  <java.version>1.8</java.version>
24  <spring-cloud.version>Greenwich.M3</spring-cloud.version>
25  </properties>
26  <dependencies>
27  <dependency>
28  <groupId>org.springframework.cloud</groupId>
29  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
30  </dependency>
31  <dependency>
32  <groupId>org.springframework.boot</groupId>
33  <artifactId>spring-boot-starter-test</artifactId>
34  <scope>test</scope>
35  </dependency>
36  </dependencies>
37  <dependencyManagement>
38  <dependencies>
39  <dependency>
40  <groupId>org.springframework.cloud</groupId>
41  <artifactId>spring-cloud-dependencies</artifactId>
42  <version>${spring-cloud.version}</version>
43  <type>pom</type>
44  <scope>import</scope>
45  </dependency>
46  </dependencies>
47  </dependencyManagement>
48  <build>
49  <plugins>
50  <plugin>
51  <groupId>org.springframework.boot</groupId>
52  <artifactId>spring-boot-maven-plugin</artifactId>
53  </plugin>
54  </plugins>
55  </build>
57  <repositories>
58  <repository>
59  <id>spring-milestones</id>
60  <name>Spring Milestones</name>
61  <url>https://repo.spring.io/milestone</url>
62  <snapshots>
63  <enabled>false</enabled>
64  </snapshots>
65  </repository>
66  </repositories>
67 </project>
4.打包:mvn clean install -Dmaven.test.skip=true
5.启动注册中心服务端:java -jar eureka-0.0.1-SNAPSHOT.jar

原文链接:https://www.cnblogs.com/CodeKjm/p/10367326.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:spring_06装配bean_2

下一篇:Java 访问权限修饰符 与 非访问权限修饰符