SpringCloud项目
SpringCloud微服务。之前的SpringBoot是单体架构。但是这种单体架构会出现一个模块有问题,和可能导致整个项目的崩溃,各个模块必须使用同一技术进行开发,各个模块很难根据实际的情况选择适合的技术框架,后期交付成本高的问题。
创建SpringCloud项目的步骤。
- 创建父工程依赖
<!-- 这是一个父级项目 引入的依赖都可被后继的子项目进行引用 -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.0.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- dependencyManagement 帮助实现项目的依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
- 子工程的依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
- 创建配置文件application.yml 添加Eureka Server的相关配置
server:
port: 8761
eureka:
client:
#是否将当前的这个Eureka Server 作为客户端进行注册
register-with-eureka: false
#是否获取其他Eureka Server服务的数据
fetch-registry: false
service-url:
default-zone: http:localhost:8761/eureka
- 创建项目的启动类
@SpringBootApplication
//EnableEurekaServer` 声明当前类是一个Eureka Server 微服务 提供服务的注册功能,//即注册中心
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EnableEurekaServer.class, args);
}
}