我不知道大家有没有遇到过,很多面试官上来就是谈谈你对分布式的理解,接着就是什么是微服务,再接着就是SpringCloud用过?能不能谈一谈,同一个坑我踩了好多次,面试的时候总是祈祷不要来这些了,然而上天从来没有把我的祷告听进去,那也好,就来学一波吧!最好的理解就是自己玩一下这个框架!
由于时间关系快1点了,我先暂时编辑写一个注册中心的搭建,底下每天我写一些,一是相当于笔记,二是希望有人给我提建议。
我先谈一谈搭建springboot+springcloud这个框架:
1.首先搭建一个搭建一个注册中心euerka(这边没坑非常简单)
(1) 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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.rhkj</groupId> <artifactId>yun</artifactId> <version>0.0.1-SNAPSHOT</version> <name>yun</name> <description>Demo project for Spring Boot</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Finchley.RELEASE</spring-cloud.version> </properties> <dependencies> <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-test</artifactId> <scope>test</scope> </dependency> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
(2)application-dev.properties
server.port=8081 eureka.instance.hostname=localhost eureka.instance.client.registerWithEureka=false eureka.instance.client.fetchRegistry=false eureka.instance.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/ spring.application.name= demo-eureka
(3)eurekaApplication
@EnableEurekaServer @SpringBootApplication public class YunApplication { public static void main(String[] args) { SpringApplication.run(YunApplication.class, args); } } 4. 启动YunApplication,浏览器输入http://localhost:8081/,显示如下证明euerka搭建成功