从零开始搭建开发springcloud项目遇到的所有问题整理,新入springcloud坑的同学,遇到的问题,几乎都可以在这找到问题答
此贴现在还在更新中
因为我的项目未开发完
ps:项目没啥进度, 但是遇到的问题一天比一天多 o(╥﹏╥)o 这可咋整 (´-ι_-`)
1.Parameter 0 of method loadBalancerWebClientBuilderBeanPostProcessor
具体错误描述如下:
Parameter 0 of method loadBalancerWebClientBuilderBeanPostProcessor in org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration required a bean of type ‘org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction’ that could not be found.
可以看到很明显是缺少了负载均衡的依赖。
解决方案:
一.引入负载均衡依赖,如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
验证可启动成功。
二.怀疑是springcloud
升级导致的问题,所以做降级,这里要注意降级时候spring boot
和spring cloud
的对应关系
参考降级:
spring boot
原版本:2.6.1
spring boot
降级后版本:2.3.2.RELEASE
spring cloud
原版本:2021.0.0
spring cloud
降级后版本:Hoxton.SR7
验证后可启动成功。
2.java: 找不到符号 方法 getUserId() 位置: 类型为io.renren.modules.sys.entity.SysUserTokenEntity
错误信息(以下错误只是代表节选, 正常会有很多提示找不到):
java: 找不到符号
符号: 方法 getExpireTime()
位置: 类型为io.renren.modules.sys.entity.SysUserTokenEntity的变量 tokenEntity
错误原因:
用的2021
版本的idea
,内置了lombok
插件。但是和高版本的idea
不兼容。换个版本就可以了。
解决办法:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
3.[ERROR] Some problems were encountered while processing the POMs:
Maven打包报错内容:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ line 79, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-amqp:jar is missing. @ line 23, column 25
[ERROR] 'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 29, column 25
[ERROR] 'dependencies.dependency.version' for org.projectlombok:lombok:jar is missing. @ line 35, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-test:jar is missing. @ line 41, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.amqp:spring-rabbit-test:jar is missing. @ line 47, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-web:jar is missing. @ line 53, column 25
[ERROR] 'dependencies.dependency.version' for com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar is missing. @ line 59, column 25
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.example:mq_example:1.0-SNAPSHOT (/Users/jerry/yangyi/mq_example/pom.xml) has 7 errors
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-amqp:jar is missing. @ line 23, column 25
[ERROR] 'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 29, column 25
[ERROR] 'dependencies.dependency.version' for org.projectlombok:lombok:jar is missing. @ line 35, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-test:jar is missing. @ line 41, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.amqp:spring-rabbit-test:jar is missing. @ line 47, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-web:jar is missing. @ line 53, column 25
[ERROR] 'dependencies.dependency.version' for com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar is missing. @ line 59, column 25
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Process finished with exit code 1
遇到此类问题, 一定是某个依赖未给版本号, 导致读入依赖配置时, 不能正常匹配依赖版本, 导致报错
问题依赖:
修改:
如果只想在子类工程中引用这个依赖使用,在子类工程的maven
依赖中用:<dependencyManagement></dependencyManagement>
标签包住即可,如果子父类通用,直接添加到父类,不用包.
如下例子:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
</dependencyManagement>
4.Failure to find com.alibaba.cloud:spring-cloud-alibaba-dependencies:pom:2.1.1.BUILD-SNAPSHOT
添加spring-cloud-alibaba-dependencies
1.spring-cloud-alibaba-dependencies版本如果和springboot版本冲突,会导致无法正确导入依赖,pom文件飘红,如图:
(此时直接检查各组件引用的springcloud版本,发现有不一样的改掉基本就可以解决问题)
2.哪怎么正确添加spring-cloud-alibaba-dependencies呢?答案现在揭晓:
2.1访问GitHub上的spring-cloud-alibaba-dependencies开源项目
导入依赖,项目就可以正常运行了!
刷新, pom文件不再飘红。
附:spring-cloud-alibaba
官方版本号对照文档
github.com/alibaba/spr…
以springcloud alibaba 2.4
为分界线,
由于 Spring Boot 2.4+
和以下版本之间变化较大,目前企业级客户老项目相关 Spring Boot
版本仍停留在 Spring Boot 2.4
以下,为了同时满足存量用户和新用户不同需求,社区以 Spring Boot 2.4
为分界线,同时维护 2.2.x
和 2021.x
两个分支迭代。
老版本升级新版要注意版本兼容问题,新开发的项目也要注意兼容。
5.Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
1.问题描述:
未能配置数据源:url
属性未指定,无法配置嵌入式数据源。
Reason:Failed to determine a suitable driver class.
无法确定合适的驱动程序类别。
2.问题解决:
1.问题分析:
在程序的配置文件中添加引入了数据库驱动依赖包, springboot
程序就自动去进行数据连接, 但是因为没有配置数据库的连接信息, 所以就会报错。
2.问题解决:
(1)去掉自动连接:
在未配置数据库连接信息时,可以将入口类中的注解修改为以下代码:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
即添加(exclude = {DataSourceAutoConfiguration.class})
, 排除自动连接。
(2)配置数据源信息:
在application.yml
中配置数据库的连接信息,运行程序就不会报错。
5.Param 'serviceName' is illegal, serviceName is blank
1.问题详细:
namingService subscribe failed, properties:NacosDiscoveryProperties{serverAddr='localhost:8848', username='', password='', endpoint='', namespace='', watchDelay=30000, logName='', service='', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.11.1', networkInterface='', port=-1, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, instanceEnabled=true, ephemeral=true, failureToleranceEnabled=false}, ipDeleteTimeout=null, failFast=true}
2.原因:
在application.yml中缺少nacos识别的必要参数
3.解决方法:
spring:
application:
name: test
cloud:
nacos:
discovery:
server-addr: localhost:8848
在maven
引用没问题的情况下, 出现以上报错, 第一时间检查application name
和nacos
服务地址配置