今天写一个接口,所有的都写完了后来测试。整个项目是用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使用还不熟,不过这一点都忘记了的确不应该,记录一下。