springcloud 学习笔记

//问题很大  重新开始 先记录一下

今天把以前的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>

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值