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

请问一下,我这样写有什么问题嘛?为什么通过方法注入找不到beanId?

@Configuration
@ComponentScan("com.qin5")
public class TestConfiguration5 {

}


@Component(value = "testBean15")
@Scope("singleton")
public abstract class TestBean5 {
    @Lookup
    public abstract AnotherBean5 createAnotherBean5();

    public void printBean() {
        System.out.println(createAnotherBean5());
    }
}

@Component
@Scope("prototype")
public class AnotherBean5 {
}
@Test
public void test5() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration5.class);
    TestBean5 testBean1 = context.getBean("testBean15", TestBean5.class);
    testBean1.printBean();
    testBean1.printBean();
    testBean1.printBean();
    testBean1.printBean();
    testBean1.printBean();
    testBean1.printBean();

}

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'testBean15' is defined	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:702)	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1180)	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082)	at com.qin.BeanTest.test5(BeanTest.java:78)	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:59)	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:305)	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:365)	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:330)	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:78)	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:328)	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:65)	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:305)	at org.junit.runners.ParentRunner.run(ParentRunner.java:412)	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


正在回答

1 回答

TestBean5  这个类是否在你@ComponentScan("com.qin5") 扫描的包路径下呢?
0 回复 有任何疑惑可以回复我~
#1

慕丝6064964 提问者

在的呀.
2019-08-05 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问一下,我这样写有什么问题嘛?为什么通过方法注入找不到beanId?

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