springCloud学习笔记一 注册中心搭建
程序员文章站
2022-07-13 09:39:49
...
1.pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
2.启动类Application
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableEurekaClient
public class Application {
@Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(Application .class, args);
}
}
3.配置文件application.yml
server:
port: 8000 #服务端口
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false #是否将eureka自身作为应用注册到eureka注册中心
fetch-registry: false #为true时,可以启动,但报异常:Cannot execute request on any known server
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #此处结尾必须是eureka,否则服务无法注册成功
spring:
application:
name: eureka
4.启动
下一篇: JSP有关的面试题
推荐阅读
-
详解Docker学习笔记之搭建一个JAVA Tomcat运行环境
-
SpringCloud微服务实战:一、Eureka注册中心服务端
-
Laravel框架学习笔记(一)环境搭建
-
React 入门学习笔记整理(一)——搭建环境
-
大数据学习笔记【一】:Hadoop-3.1.2完全分布式环境搭建(Windows 10)
-
SpringCloud学习笔记(7):使用Spring Cloud Config配置中心
-
Python学习笔记(一)(基础入门之环境搭建)
-
sencha touch2学习笔记(一)---环境搭建和开发工具配置
-
SpringCloud-2.X 学习笔记02 Eureka Client 搭建
-
springCloud学习笔记一 注册中心搭建