spring中No bean named xxx available錯誤
我這邊是採用spring註解來做的。
所有 ApplicationContext context = new AnnotationConfigApplicationContext(hello.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
- idea maven搭建spring報錯:No bean named 'xxx' availableIdeaMavenSpringBeanAI
- No bean named ''XXX“ availableBeanAI
- No Bean named 'Xxx' available 異常報錯BeanAI
- spring-mybatis整合:NoSuchBeanDefinitionException: No bean named 'xxx.class' availableSpringMyBatisBeanExceptionAI
- Spring中出現:No bean named 'XXX' available問題解決SpringBeanAI
- SpringBoot 學習之 No bean named ‘xxx’ availableSpring BootBeanAI
- 使用@Service註解出現No bean named 'xxxx' available]錯誤BeanAI
- No bean named 'xxx' is defined錯誤,原因及解決方案Bean
- No bean named BookServiceImpl availableBeanAI
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- Caused by:.NoSuchBeanDefinitionException: No bean named 'userInfoServiceImpl' availableBeanExceptionAI
- 報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx'is definedSpringFrameworkBeanException
- 記一次idea構建springmvc報錯:No bean named 'cacheManager' availableIdeaSpringMVCBeanAI
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'aaaa' availableSpringFrameworkBeanExceptionAI
- spring getBean(String) No bean named '' is definedSpringBean
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- QT中error: xxx does not name a type xxx錯誤QTError
- No instances available for XXXAI
- 使用Idea構建springmvc框架,出現no bean named ‘cacheManager’ is defined 錯誤。IdeaSpringMVC框架Bean
- 程式碼改造引發的NoSuchBeanDefinitionException:no bean named 'XXXX' available問題解決方案BeanExceptionAI
- kafka 錯誤: larger than available brokersKafkaAI
- 【ERROR】su user報'This account is currently not available'錯誤 for linuxErrorAILinux
- linux解決“XXX is not in the sudoers file”錯誤Linux
- spring中bean.xml的http://www.springframework.org/schema/bean報錯SpringBeanXMLHTTPFramework
- Result Maps collection already contains value for xxx.xxx.dao.BaseResultMap錯誤AI
- Git錯誤fatal: CRLF would be replaced by LF in xxxGit
- The bean ‘xxx‘, defined in class path resource , ......Bean
- 解決ubuntu系統“XXX is not in the sudoers file”錯誤Ubuntu
- 使用PyCharm時顯示的 No module named ‘xxx’PyCharm
- No bean named 'cacheManager' availablej 異常解決BeanAI
- [mac pip錯誤]Can't connect to HTTPS URL because the SSL module is not availableMacHTTPAI
- 啟動IDEA 報 failed to load jvm dll XXX 錯誤IdeaAIJVM
- Spring中bean的含義SpringBean
- Spring中Bean的作用域SpringBean
- 【翻譯】在Spring WebFlux中處理錯誤SpringWebUX
- pyecharts安裝後import錯誤 ImportError: No module named 'pyecharts_snapshot'EchartsImportError
- SVN chechout failed: xxx is not valid as filename in directory svn檢出錯誤AI