微服务架构
SpringCloud是基于SpringBoot实现的云应用开发工具
随着新需求的不断增加,企业更新和修复大型整体式的项目比较困难。那么微服务到底是什么呢?
其实微服务是一种架构风格,一个大型复杂的软件或者说是项目由一个或者多个小的微服务组成。系统中的每个微服务都可以被独立部署。各个微服务之间是松耦合的。每个微服务只关注于一个任务或者说是整个复杂项目中的一个功能。比如购物车功能,订单功能。
下面是建立SpringCloud的两个不同的方法:
1.先通过 http://start.spring.io/ 这个网站 新建一个springboot的新项目。
2.解压压缩包 并使用idea的导入方法进行导入
File–>New–>Project from Existing Sources…
或者直接使用idea的File–>new–>Project即可
一直点击next 在这里可以根据需要更改自己的项目名称:
然后一直next创建出新的项目
然后在pom.xml中加入配置文件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
在dependencies外面加
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
就可以了
然后在Application的类上加注解
@EnableEurekaServer
然后创建服务注册中心 需要在application.properties的文件里加入
配置文件的信息
spring.application.name=eureka-server
server.port=1001(服务中心的端口设置为了1001)
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
即可创建一个基本的SpringCloud项目