//问题很大 重新开始 先记录一下
今天把以前的springboot项目加上springcloud
具体springcloud的用途这里不写了 有好多博客已经介绍的很清楚了
一边写 一边记录 主要是记录一下遇到的问题 方便下次遇到时要再去找资料
-----------------------开始第一步--------------------------
首先第一步吧application.properties 换成application.yaml
发现还是yaml文件好用
百度有现成的properties转yaml的网页 直接转一下就行了
但是转不了注释 要自己在加一下
直接转过来的yaml有的会有错误 要自己排除
---------------------第二步------------------
加依赖
pom文件有里有两处要改
现在这个标签中 <dependencies></dependencies>
加入这几个依赖
<!--springcloud 配置-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${springcloud.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-config -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>${springcloud.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>${springcloud.version}</version>
</dependency>
${springcloud.version}我这里写的是3.0.3
然后在<dependencies></dependencies>标签外
加入
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR12</version>
<type>pom</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
----------------------第二步 修改yaml文件-----------------------
yaml文件里加了
eureka:
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: http://localhost:8080/eureka
----------------------问题汇总-------------------
问题1:
Error creating bean with name 'configurationPropertiesBeans'
springcloud版本与springboot版本不搭配
我这里springboot版本是2.4.1
更改springcloud-dependencies
版本到Hoxton.SR12 问题解决
问题2:
Description:
No spring.config.import property has been defined
解决办法在报错下面已经告诉了
Action:
Add a spring.config.import=configserver: property to your configuration.
If configuration is not required add spring.config.import=optional:configserver: instead.
To disable this check, set spring.cloud.config.enabled=false or
spring.cloud.config.import-check.enabled=false.
在yaml文件中加入
spring:
cloud:
config:
enabled: false
问题解决
问题3:
启动报错
Error creating bean with name 'eurekaServerContext'
Error creating bean with name 'eurekaServerBootstrap'
解决办法 加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>