spring boot启动报Error creating bean with name ‘xxx‘:

在启动SpringBoot项目时遇到Errorcreatingbeanwithname的异常,问题源于在AutoMapperConfig配置类中定义的autoMapper Bean。经过debug发现,错误的根本原因是工作空间中多了一个空格,导致了依赖注入失败和空指针异常。修复这一小细节后,项目成功启动,提醒开发者编程时需注意代码规范和细节。
摘要由CSDN通过智能技术生成

#spring boot启动报Error creating bean with name ‘xxx’: Injection of resource dependencies failed; nested exception is

##我在启动springboot项目时候保错

由于之前都没有报错,ctrl+v 别人的代码之后,报错的,有Error creating bean with name、空指针等等,网上查了许多都没起作用,然后打断点进行解决的,下面一起看看我的异常。

###1、先看报错的源码
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.dreamyoung.mprelation.AutoMapper;

@Configuration
public class AutoMapperConfig {
@Bean
public AutoMapper autoMapper() {
return new AutoMapper(new String[] {“com.jincheng.bean”}); //配置实体类所在目录(可多个,暂时不支持通过符*号配置)
}

}

###2、报错信息
Error creating bean with name ‘webSecurityConfig’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘loginAuthenticationProvider’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘usersServiceImpl’: Unsatisfied dependency expressed through field ‘autoMapper’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘autoMapper’ defined in class path resource [com/xxx/config/AutoMapperConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.dreamyoung.mprelation.AutoMapper]: Factory method ‘autoMapper’ threw exception; nested exception is java.lang.NullPointerException: null
3、最初以为jar包没下载等等,由于多方查证无法解决,只能debugger一步一步查看,最后发现是工作空间多写了一个空格,才出现这样的错
![在这里插入图片描述](https://img-blog.csdnimg.cn/c2c527可以明显看出工作空间多了个空格

以后还得小心点,规范命名。。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值