Spring Cloud注意点
创建工程要规范
<?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> <groupId>cn.csq.springcloud</groupId> <artifactId>cloud2020</artifactId> <version>1.0-SNAPSHOT</version> <!--子模块--> <modules> <module>cloud-provider-payment8001</module> </modules> <packaging>pom</packaging> <!--统一管理jar包版本--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <junit.version>4.12</junit.version> <log4j.version>1.2.17</log4j.version> <lombok.version>1.16.18</lombok.version> <mysql.version>5.1.47</mysql.version> <druid.version>1.1.16</druid.version> <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version> <druid.spring.boot.version>1.1.10</druid.spring.boot.version> </properties> <!--子模版继承之后,提供作用:锁定版本+子modlue不用写groupId和version--> <dependencyManagement> <dependencies> <!-- Spring Boot 2.2.2 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.2.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Spring Cloud Hoxton.SR1--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR1</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Spring Cloud alibaba 2.1.0.RELEASE --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.1.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency>--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>${druid.spring.boot.version}</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis.spring.boot.version}</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> </dependencies> </dependencyManagement> </project>
项目的一些配置
项目依赖
maven配置
项目编码
开启注解支持
项目编译环境
显示忽略
### Run Dashboard
在2019之后idea改为了services面板
在微服务项目中,通常启动多个不同端口的项目,这时就需要这样的面版

### 自动热部署
- Adding devtools to your project
添加devtools依赖到工程
```xml
<!-- 热部署Devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
```
- Adding plugin to your pom.xml
添加插件到pom文件中
```xml
<build>
<!-- 填你自己的工程名字-->
<finalName>cloud 2020</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
```
- Enabling automatic build

- Update the value of
开启热部署
`ctrl + shift + Alt +/`

Registry


- 重启IDEA
- 该配置只能使用在开发阶段,生产上线阶段千万不能使用
nacos:它的server就是一个web容器其实,服务注册什么的都是一个http请求。
ribbon:原理:发一个请求去服务注册中心,然后获取到对应服务名称的服务实例列表,存储到本地,然后他是有一个时间的间隔,每隔多久去查找一次对应的服务实例列表,以便于添加服务实例和减少服务实例。
feign:底层使用了动态代理,然后调用ribbon,根据服务名去查找可用的服务实例列表