按源码运行测试时候还是报错

来源:5-4 Advice应用(上)

qq_怀念_10

2018-03-12 09:56

所有的jar包都有,为什么还是报错?

写回答 关注

2回答

  • qq_怀念_10
    2018-03-13 11:01:31

    bean用的是老师源代码的

    <bean id="injectionService" class="com.imooc.ioc.injection.service.InjectionServiceImpl">

            <constructor-arg name="injectionDAO" ref="injectionDAO"></constructor-arg>

            </bean>

            

            <bean id="injectionDAO" class="com.imooc.ioc.injection.dao.InjectionDAOImpl"></bean>

    然后用junit跑testCons方法,报错如下

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'injectionService' defined in class path resource [spring-injection.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.imooc.ioc.injection.dao.InjectionDAO]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?

    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:733)

    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

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

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

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

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

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

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

    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)

    at com.imooc.test.base.UnitTestBase.before(UnitTestBase.java:27)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)


  • stt54321
    2018-03-12 15:31:20

    你要把具体的报错贴出来,别人才能帮你看看

Spring入门篇

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

268785 学习 · 963 问题

查看课程

相似问题