spring问题:初始化bean失败

本文分析了Spring框架中因未找到指定Bean定义而导致的BeanCreationException异常,通过示例代码展示了错误发生的情景,并探讨了解决方案。

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

org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'businessBean' defined in file [d:/workspace/TestSpring/bean.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'businessTarget' is defined
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'businessTarget' is defined
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:350)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:920)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:460)
 at org.springframework.aop.framework.ProxyFactoryBean.isNamedBeanAnAdvisorOrAdvice(ProxyFactoryBean.java:378)
 at org.springframework.aop.framework.ProxyFactoryBean.checkInterceptorNames(ProxyFactoryBean.java:355)
 at org.springframework.aop.framework.ProxyFactoryBean.setBeanFactory(ProxyFactoryBean.java:213)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1101)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:281)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
 at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:93)
 at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:77)
 at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:67)
 at aop.Test.main(Test.java:9)
Exception in thread "main"  

是什么原因?bean的路径我也查过了!

测试类:

 ApplicationContext ac = new FileSystemXmlApplicationContext("bean.xml");
        BusinessInterface businessBean = (BusinessInterface) ac
                .getBean("businessBean");
        businessBean.hello();

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值