微服务分布式事务实战(三)SpringCloud注册中心编写和测试

释放双眼,带上耳机,听听看~!

SpringCloud注册中心编写和测试
(1)创建注册中心工程
微服务分布式事务实战(三)SpringCloud注册中心编写和测试
(2)添加jar包 pom.xml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3      <modelVersion>4.0.0</modelVersion>
4      <groupId>com.jh</groupId>
5      <artifactId>RegisterCenter </artifactId>
6      <version>0.0.1-SNAPSHOT</version>
7      <packaging>jar</packaging>
8    
9      <name> RegisterCenter </name>
10      <url>http://maven.apache.org</url>
11      
12      <properties>
13        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14      </properties>
15
16  
17<!--  1 spring boot parent  -->
18    <parent>
19        <groupId>org.springframework.boot</groupId>
20        <artifactId>spring-boot-starter-parent</artifactId>
21        <version>1.4.3.RELEASE</version>
22        <relativePath/>
23    </parent>
24       <!-- spring    -->
25
26    <dependency>
27            <groupId>org.springframework.boot</groupId>
28            <artifactId>spring-boot-starter</artifactId>
29        </dependency>
30  
31         <!--2 注册服务中心   -->
32        <dependency>
33            <groupId>org.springframework.cloud</groupId>
34            <artifactId>spring-cloud-starter-eureka-server</artifactId>
35        </dependency>
36        <!-- spring  boot 测试 -->
37       <dependency>
38            <groupId>org.springframework.boot</groupId>
39            <artifactId>spring-boot-starter-test</artifactId>
40            <scope>test</scope>
41        </dependency>
42                
43   <!-- spring cloud  依赖版本 -->
44
45      </dependencies>
46         <dependencyManagement>
47            <dependencies>
48                <dependency>
49                    <groupId>org.springframework.cloud</groupId>
50                    <artifactId>spring-cloud-dependencies</artifactId>
51                    <version>Dalston.SR3</version>
52                    <type>pom</type>
53                    <scope>import</scope>
54                </dependency>
55            </dependencies>
56        </dependencyManagement>
57    </project>
58
59

(3) 编写主程序


1
2
3
4
5
6
7
8
9
1@EnableEurekaServer // 开启注册发现
2@SpringBootApplication // spring boot应用程序
3public class EurekaServer {
4   public static void main(String[] args) {
5       SpringApplication.run(EurekaServer.class, args);
6   }
7}
8
9

(4)配置文件application.properties


1
2
3
4
5
6
7
1server.port=8001
2eureka.instance.hostname=localhost
3eureka.client.register-with-eureka=false
4eureka.client.fetch-registry=false
5eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
6
7

(5)测试:


1
2
3
4
1 打开浏览器输入http://loclalhost:8001
2 系统返回
3
4

微服务分布式事务实战(三)SpringCloud注册中心编写和测试

给TA打赏
共{{data.count}}人
人已打赏
安全网络

CDN安全市场到2022年价值76.3亿美元

2018-2-1 18:02:50

安全经验

Apche Shiro 1.2.4 发布,轻量安全框架

2015-8-1 11:12:22

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索