springCloud实践报错整理

本文整理了搭建Spring Cloud时的常见报错。如因Spring Boot版本兼容性报错,可修改pom.xml配置;Spring Boot JPA的IllegalArgumentException异常,可能是实体类未加注解或未按约定扫描;ClassNotFoundException报错,可在pom文件添加依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava
搭建spring cloud的时候,报以下错误:

 java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

是由于spring boot版本兼容性导致的,在pom.xml中修改配置文件如下,重启成功!

		<!--- 修改前 -->
	<parent>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-parent</artifactId>
			<version>2.1.6.RELEASE</version>
			<relativePath>../pom.xml</relativePath>
		</parent>
    <!-- 修改后-->
  <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.2.RELEASE</version>
		<relativePath>../pom.xml</relativePath> 
	</parent>

springboot与springcloud版本对应关系可参考 https://www.cnblogs.com/zhuwenjoyce/p/10261079.html

2、spring boot jpa-java.lang.IllegalArgumentException: Not a managed type异常问题解决方法

JPA实体类没有被扫描到,导致这样的情况有以下几种可能

1 实体类没有加上@Entity注解

    对应解决方法在实体类上加上@Entity即可解决问题

2 没有按照SpringBoot的约定,默认扫描(application.java 入口类相对的兄弟包及其子包)

    2.1        将application.java(入口类)放置到更高层级的包,使得项目结构符合SpringBoot约定扫描的规则
    2.2        在启动类中添加扫描注解
            2.2.1        @ComponentScan(basePackages = "com.boot.demo.xxx.*.*")
                            用于扫描@Controller @Service
            2.2.2        @EnableJpaRepositories(basePackages = "com.boot.demo.xxx.*.dao") 
                            用于扫描Dao @Repository
           2.2.3        @EntityScan("com.boot.demo.xxx.*.*")
                            用于扫描JPA实体类 @Entity

转自:https://blog.youkuaiyun.com/heyewu4107/article/details/78942393

3、Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig

pom文件中添加依赖

org.apache.commons
commons-pool2
2.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值