spring中No bean named xxx available錯誤
我這邊是採用spring註解來做的。
ApplicationContext context = new AnnotationConfigApplicationContext(配置類.class);填寫的是配置類(也就是宣告瞭@Configurable註解的類)
看一下你的測試類中引用配置檔案對了沒有
ApplicationContext context = new AnnotationConfigApplicationContext(hello.class);
hello bean = context.getBean("He", hello.class);
bean.show();
我的配置檔案是BeanConfig才對,而我測試類那邊寫了hello.class,所以會報錯
只要把引用配置檔案那邊改過來就可以了,改成Beanconfig.class
ApplicationContext context = new AnnotationConfigApplicationContext(BeanConfig.class);
hello bean = context.getBean("He", hello.class);
bean.show();
報錯內容
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘He’ available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:808)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1114)
at com.LSC.MyTest.sayHello(MyTest.java:25)
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:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
相關文章
- Spring:錯誤No bean named 'xxxxxxx' availableSpringBeanAI
- No bean named ''XXX“ availableBeanAI
- 使用@Service註解出現No bean named 'xxxx' available]錯誤BeanAI
- No Bean named 'Xxx' available 異常報錯BeanAI
- idea maven搭建spring報錯:No bean named 'xxx' availableIdeaMavenSpringBeanAI
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- Spring中出現:No bean named 'XXX' available問題解決SpringBeanAI
- No bean named BookServiceImpl availableBeanAI
- spring-mybatis整合:NoSuchBeanDefinitionException: No bean named 'xxx.class' availableSpringMyBatisBeanExceptionAI
- No bean named 'xxx' is defined錯誤,原因及解決方案Bean
- SpringBoot 學習之 No bean named ‘xxx’ availableSpring BootBeanAI
- Spring Boot學習之No bean named 'entityManagerFactory' available異常Spring BootBeanAI
- Caused by:.NoSuchBeanDefinitionException: No bean named 'userInfoServiceImpl' availableBeanExceptionAI
- MyBatis對映錯誤:There is no setter for property named xxxMyBatis
- 程式碼改造引發的NoSuchBeanDefinitionException:no bean named 'XXXX' available問題解決方案BeanExceptionAI
- 記一次idea構建springmvc報錯:No bean named 'cacheManager' availableIdeaSpringMVCBeanAI
- 報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx'is definedSpringFrameworkBeanException
- spring getBean(String) No bean named '' is definedSpringBean
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'aaaa' availableSpringFrameworkBeanExceptionAI
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxxxx' iSpringFrameworkBeanException
- SpringMVC莫名其妙出現No bean named 'cacheManager' is defined錯誤SpringMVCBean
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- 使用Idea構建springmvc框架,出現no bean named 'cacheManager' is defined 錯誤IdeaSpringMVC框架Bean
- 使用Idea構建springmvc框架,出現no bean named ‘cacheManager’ is defined 錯誤。IdeaSpringMVC框架Bean
- 報錯No bean named ' is defined的原因和解決方案Bean
- QT中error: xxx does not name a type xxx錯誤QTError
- spring與mybatis中注入了卻總提示no bean namedSpringMyBatisBean
- kafka 錯誤: larger than available brokersKafkaAI
- yum安裝xxx包時出錯,提示No package xxx available.PackageAI
- Package ssh is not available, but is referred to by another package 錯誤PackageAI
- No instances available for XXXAI
- Spring中Bean及@Bean的理解SpringBean
- Spring中的BeanSpringBean
- NBU available_media 命令執行錯誤AI
- spring中bean.xml的http://www.springframework.org/schema/bean報錯SpringBeanXMLHTTPFramework
- PostgreSQL cache lookup failed for type XXXX 錯誤SQLAI
- 關於報錯Error creating bean with name 'xxxxx': Invocation of init method....ErrorBean
- pip安裝錯誤:ImportError: No module named 'pkg_resources'ImportError