springCloud分布式事务实战(三)SpringCloud注册中心编写和测试
SpringCloud注册中心编写和测试
(1)创建注册中心工程
(2)添加jar包 pom.xml
4.0.0
com.jh
RegisterCenter
0.0.1-SNAPSHOT
jar
RegisterCenter
http://maven.apache.org
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/>
</parent>
org.springframework.boot
spring-boot-starter
<!--2 注册服务中心 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!-- spring boot 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
org.springframework.cloud
spring-cloud-dependencies
Dalston.SR3
pom
import
(3) 编写主程序
@EnableEurekaServer // 开启注册发现
@SpringBootApplication // spring boot应用程序
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(EurekaServer.class, args);
}
}
(4)配置文件application.properties
server.port=8001
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://{server.port}/eureka/
(5)测试:
打开浏览器输入http://loclalhost:8001
系统返回