按照老师敲的service层 拼写检查过了 不知道哪里出错 有人能帮忙看下吗 错误贴在下面了 谢谢

来源:4-1 使用集成测试Service逻辑

慕移动7208282

2017-04-24 20:17

严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@6cd8737] to prepare test instance [service.SeckillServiceTest@13d9cbf5]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service.SeckillServiceTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private service.SeckillService service.SeckillServiceTest.seckillService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.SeckillService] 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.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:259)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:261)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:219)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
    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:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private service.SeckillService service.SeckillServiceTest.seckillService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.SeckillService] 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$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 26 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.SeckillService] 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.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 28 more

四月 24, 2017 7:32:00 下午 org.springframework.context.support.GenericApplicationContext doClose
信息: Closing org.springframework.context.support.GenericApplicationContext@6a1aab78: startup date [Mon Apr 24 19:31:58 CST 2017]; root of context hierarchy

写回答 关注

7回答

  • 小小男爵home
    2017-05-07 14:20:28
    已采纳

    spring-service.xml文件里边的这句话你写了么?

    <context:component-scan base-package="org.seckill.service"/>

    慕圣4396... 回复慕移动720...

    你问题解决没,我也遇见相同的问题了

    2017-05-13 21:49:39

    共 2 条回复 >

  • qq_慕尼黑5025872
    2020-10-26 18:59:45

    找到原因了,是service层把@service注解了,去SeckillServiceImpl里加上@service就可以了

  • qq_慕尼黑5025872
    2020-10-26 17:50:53

    解决了为啥不发出来原因?

  • weibo_慕田峪6425051
    2019-06-05 13:28:06

    https://img4.mukewang.com/5cf752d40001e63315280866.jpg

    这里接口不需要注入@Service吗

    小段

    我也有这个疑问 目前好像这个接口没啥用

    2019-07-23 11:32:07

    共 1 条回复 >

  • qq_秀策丶_0
    2018-04-26 23:18:29

    我想问一下你这个是怎么解决的 我没有解决掉 跟你一样的错误


  • 慕粉4293687
    2017-04-25 16:24:29

    @ContextConfiguration({"classpath:spring/spring-dao.xml",
    "classpath:spring/spring-service.xml"})

    那我估计你这里错了吧,service xml配置没有写就不会加载这个bean

    慕移动720...

    service xml和 @ContextConfiguration({"classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml"})这句还有SeckillServiceTest和老师写的一样啊

    2017-04-25 16:55:34

    共 1 条回复 >

  • 慕粉4293687
    2017-04-25 15:23:50

    No qualifying bean of type [service.SeckillService] found

    spring容器中没有这个bean的实例,大概率你没有在SeckillService类上加 @Service 或者@Component


    慕移动720... 回复小猫咪吃鼠片

    controller层没学到呢。。这不就是service层吗

    2017-04-25 16:48:34

    共 3 条回复 >

Java高并发秒杀API之Service层

Java实现高并发秒杀API,介绍秒杀业务Service层的设计和实现

59897 学习 · 137 问题

查看课程

相似问题