【ERROR】Exception in thread “main“ org.springframework.beans.factory.NoSuchBeanDefinitionException

简介: 【ERROR】Exception in thread “main“ org.springframework.beans.factory.NoSuchBeanDefinitionException

使用spring注解开发时候报错:


Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'bookDao' available


Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'bookDao' available
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:892)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1318)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1132)
  at com.zcongfly.app.App.main(App.java:11)


在排除:


  1. applicationContext.xml配置文件没有进行context扫描:


  1. 文件扫描路径错误


  1. @Component("className")及其衍生注解类名定义与main入口处中getBean("className")不一致(一般是首字母大小写出错):@Component("BookDao")在main中写成getBean("bookDao")

之后。


查看当前项目使用的spring版本


如果是spring6以上的版本,把版本降为spring5就能正常运行!


JDK17+spring6.0.5按照之前版本注解开发的逻辑写的代码,会直接报No bean named 'bookDao' available的错误!

目录
相关文章
|
7月前
|
搜索推荐 Java 开发者
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 问题处理
【5月更文挑战第14天】org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 问题处理
889 1
|
5月前
|
Java Spring
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException(Spring循环依赖问题)
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException(Spring循环依赖问题)
123 0
|
5月前
|
XML Java Apache
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘t
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘t
|
5月前
|
Java Apache Spring
若依配Mapper,若依修改Caused by: org.springframework.beans.factory.BeanCreationException: Error creating
若依配Mapper,若依修改Caused by: org.springframework.beans.factory.BeanCreationException: Error creating
|
6月前
|
Java
Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException:
Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException:
|
Java 微服务 Spring
【Java异常】Spring boot启动失败@org.springframework.beans.factory.annotation.Autowired(required=true)
【Java异常】Spring boot启动失败@org.springframework.beans.factory.annotation.Autowired(required=true)
331 0
|
7月前
|
SQL 关系型数据库 MySQL
c.t.t.handler.GlobalExceptionHandler : 捕获异常:org.springframework.jdbc.BadSqlGrammarException:
c.t.t.handler.GlobalExceptionHandler : 捕获异常:org.springframework.jdbc.BadSqlGrammarException:
59 0
|
7月前
|
安全 Java 数据库连接
java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/YamlProcessor$StrictMapAppe
java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/YamlProcessor$StrictMapAppe
73 0
|
7月前
|
容器
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
115 0
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServer
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServer