微服务SpringCloud(一)

Spring Cloud微服务(一)

什么是Spring Cloud

简单来说,Spring Cloud是一个微服务框架的规范,注意,只是规范,他不是任何具体的框架。Spring Cloud 为最常见的分布式系统模式提供了一种简单且易于接受的编程模型,帮助开发人员构建有弹性的、可靠的、协调的应用程序。Spring Cloud 构建于 Spring Boot 之上,使得开发者很容易入手并快速应用于生产中。

 

新建Spring Cloud项目

选择Eureka server就可以新建eureka注册中心了。

微服务SpringCloud(一)_第1张图片

 

 

 

pom.xml

"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.0modelVersion> <parent> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-parentartifactId> <version>2.1.4.RELEASEversion> <relativePath/>  parent> <groupId>com.spcgroupId> <artifactId>eurekaserverartifactId> <version>0.0.1-SNAPSHOTversion> <name>eurekaservername> <description>Demo project for Spring Bootdescription> <properties> <java.version>1.8java.version> <spring-cloud.version>Greenwich.SR1spring-cloud.version> properties> <dependencies> <dependency> <groupId>org.springframework.cloudgroupId> <artifactId>spring-cloud-starter-netflix-eureka-clientartifactId> dependency> <dependency> <groupId>org.springframework.cloudgroupId> <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId> dependency> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-testartifactId> <scope>testscope> dependency> dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloudgroupId> <artifactId>spring-cloud-dependenciesartifactId> <version>${spring-cloud.version}version> <type>pomtype> <scope>importscope> dependency> dependencies> dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> plugin> plugins> build> project>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

使用 @EnableEurekaServer 来说明项目是一个 Eureka

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }

 

 

 

 

 

 

 

 

 

 

 

 

修改配置文件

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

 

 

 

 

 

 

 

 

 

 

 

 

运行 EurekaServerApplication 类,启动项目,访问项目 http://localhost:8761/

微服务SpringCloud(一)_第2张图片

 

你可能感兴趣的:(微服务SpringCloud(一))