为了账号安全,请及时绑定邮箱和手机立即绑定

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

严重: 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 回答

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

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

0 回复 有任何疑惑可以回复我~
#1

慕移动7208282 提问者

扫描我写了 已经找到出错原因了 因为包的位置没有对 导致的扫描扫描不到 感谢了
2017-05-08 回复 有任何疑惑可以回复我~
#2

慕圣4396747 回复 慕移动7208282 提问者

你问题解决没,我也遇见相同的问题了
2017-05-13 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

https://img1.sycdn.imooc.com//5cf752d40001e63315280866.jpg

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

0 回复 有任何疑惑可以回复我~
#1

小段

我也有这个疑问 目前好像这个接口没啥用
2019-07-23 回复 有任何疑惑可以回复我~

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


0 回复 有任何疑惑可以回复我~

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

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

1 回复 有任何疑惑可以回复我~
#1

慕移动7208282 提问者

service xml和 @ContextConfiguration({"classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml"})这句还有SeckillServiceTest和老师写的一样啊
2017-04-25 回复 有任何疑惑可以回复我~

No qualifying bean of type [service.SeckillService] found

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


0 回复 有任何疑惑可以回复我~
#1

慕移动7208282 提问者

谢谢解答 我整个service里只有一个@Service 在SeckillServiceimpl.java里 @Service public class SeckillServiceimpl implements SeckillService{ private Logger logger = LoggerFactory.getLogger(this.getClass()); 我看老师只写了一个@Service 不知道哪里还需要写@Service
2017-04-25 回复 有任何疑惑可以回复我~
#2

慕移动7208282 提问者 回复 小猫咪吃鼠片

controller层没学到呢。。这不就是service层吗
2017-04-25 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信