求解spring +ibatis+junit单元测试

whdrs 2012-03-13 11:46:48
[SpringJUnit4ClassRunner.java:78] : SpringJUnit4ClassRunner constructor called with [class com.lenovo.lxj.product.ClientTest].
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lenovo.lxj.product.ClientTest': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lenovo.lxj.product.dao.IClientInfoDao com.lenovo.lxj.product.ClientTest.infoDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.lenovo.lxj.product.dao.IClientInfoDao] is defined: Unsatisfied dependency of type [interface com.lenovo.lxj.product.dao.IClientInfoDao]: expected at least 1 matching bean
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:957)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:111)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:148)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lenovo.lxj.product.dao.IClientInfoDao com.lenovo.lxj.product.ClientTest.infoDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.lenovo.lxj.product.dao.IClientInfoDao] is defined: Unsatisfied dependency of type [interface com.lenovo.lxj.product.dao.IClientInfoDao]: expected at least 1 matching bean
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435)
at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:240)
... 19 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.lenovo.lxj.product.dao.IClientInfoDao] is defined: Unsatisfied dependency of type [interface com.lenovo.lxj.product.dao.IClientInfoDao]: expected at least 1 matching bean
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412)
... 21 more
[AbstractApplicationContext.java:816] : Closing org.springframework.context.support.GenericApplicationContext@127734f: display name [org.springframework.context.support.GenericApplicationContext@127734f]; startup date [Tue Mar 13 11:37:15 CST 2012]; root of context hierarchy
[AbstractApplicationContext.java:273] : Publishing event in context [org.springframework.context.support.GenericApplicationContext@127734f]: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.support.GenericApplicationContext@127734f: display name [org.springframework.context.support.GenericApplicationContext@127734f]; startup date [Tue Mar 13 11:37:15 CST 2012]; root of context hierarchy]
[DefaultSingletonBeanRegistry.java:396] : Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1dd46f7: defining beans [org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor]; root of factory hierarchy
...全文
365 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wolf863292 2012-03-14
  • 打赏
  • 举报
回复

宁波朱超 2012-03-13
  • 打赏
  • 举报
回复
???
  • 打赏
  • 举报
回复

public class ArticleServiceTest extends ServiceBase
@Test
public void test(){
ArticleServiceImpl article =context.getBean(ArticleServiceImpl.class);
int version = article.getColumnArticleVersion(5);

}

测试service层的
public abstract class ServiceBase extends Assert
{
private static String[] locations = { "service-context.xml"};
protected static ApplicationContext context = new ClassPathXmlApplicationContext(locations);

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧