org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching解決方案

今天寫一個接口,所有的都寫完了後來測試。整個項目是用spring-mvc的框架,使用ibatis做數據庫層操作。

用jetty:run啓動時老報錯。

指向的是我的一個dao類bean找不到定義,我明明寫了

@Autowired private ApiCouponPresentDao apiCouponPresentDao; 注入代碼的呀,一直沒想起來哪裏有錯。

錯誤信息是:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 

'apiWechatService': Injection of autowired dependencies failed; nested exception is 

org.springframework.beans.factory.BeanCreationException: Could not autowire field: private 

com.tongcard.api.services.ApiCouponService 

com.tongcard.api.services.impl.ApiWechatServiceImpl.apiCouponService; nested exception is 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 

'apiCouponService': Injection of autowired dependencies failed; nested exception is 

org.springframework.beans.factory.BeanCreationException: Could not autowire field: private 

com.tongcard.api.daos.ApiCouponPresentDao 

com.tongcard.api.services.impl.ApiCouponServiceImpl.apiCouponPresentDao; nested exception is 

org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type 

[com.tongcard.api.daos.ApiCouponPresentDao] found for dependency: expected at least 1 bean 

which qualifies as autowire candidate for this dependency. Dependency annotations: 

{@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at 

org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProces

sPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
	at 

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean

(AbstractAutowireCapableBeanFactory.java:1106)
	at 

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean

(AbstractAutowireCapableBeanFactory.java:517)
	at 

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean

(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject

(AbstractBeanFactory.java:294)
	at 

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton

(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean

(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean

(AbstractBeanFactory.java:193)
	at 

org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton

s(DefaultListableBeanFactory.java:609)
	at 

org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitializati

on(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh

(AbstractApplicationContext.java:469)
	at 

org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext

(ContextLoader.java:383)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext

(ContextLoader.java:283)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized

(ContextLoaderListener.java:111)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized

(ContextHandler.java:672)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized

(ServletContextHandler.java:403)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext

(ContextHandler.java:664)

 

後來查找其他的類似引用的bean,搜索後發現在spring-biz.xml裏面有配置,而這個類是我新加的,我忘記寫上配置了。

於是在配置文件中加入這個新的dao的定義後,再啓動就正常了。spring-mvc使用還不熟,不過這一點都忘記了的確不應該,記錄一下。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章