idea maven搭建spring報錯:No bean named 'xxx' available
在使用idea maven搭建spring的時候,僅有幾行程式碼和配置(spring配置放在resource下),且都沒有錯情況下,啟動依然報錯
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx' available
package com.demo;
import com.demo.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
// 1、載入spring配置檔案
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:spring.xml");
UserService userService = (UserService) applicationContext.getBean("userService");
userService.add();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="userService" class="com.demo.service.UserService"/>
</beans>
在main方法中用的是classpath的形式載入spring配置檔案,會出現這種報錯的情況。這是因為idea沒有eclipse對maven的支援好。解決辦法:右鍵resource資料夾選擇Mark Directory as > Resources Root
resource資料夾圖示會變
相關文章
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- No Bean named 'Xxx' available 異常報錯BeanAI
- spring中No bean named xxx available錯誤SpringBeanAI
- Spring:錯誤No bean named 'xxxxxxx' availableSpringBeanAI
- No bean named ''XXX“ availableBeanAI
- 使用@Service註解出現No bean named 'xxxx' available]錯誤BeanAI
- 記一次idea構建springmvc報錯:No bean named 'cacheManager' availableIdeaSpringMVCBeanAI
- Spring中出現:No bean named 'XXX' available問題解決SpringBeanAI
- No bean named BookServiceImpl availableBeanAI
- spring-mybatis整合:NoSuchBeanDefinitionException: No bean named 'xxx.class' availableSpringMyBatisBeanExceptionAI
- SpringBoot 學習之 No bean named ‘xxx’ availableSpring BootBeanAI
- Spring Boot學習之No bean named 'entityManagerFactory' available異常Spring BootBeanAI
- Caused by:.NoSuchBeanDefinitionException: No bean named 'userInfoServiceImpl' availableBeanExceptionAI
- 報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx'is definedSpringFrameworkBeanException
- No bean named 'xxx' is defined錯誤,原因及解決方案Bean
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- 程式碼改造引發的NoSuchBeanDefinitionException:no bean named 'XXXX' available問題解決方案BeanExceptionAI
- 報錯No bean named ' is defined的原因和解決方案Bean
- spring getBean(String) No bean named '' is definedSpringBean
- 使用Idea構建springmvc框架,出現no bean named 'cacheManager' is defined 錯誤IdeaSpringMVC框架Bean
- 使用Idea構建springmvc框架,出現no bean named ‘cacheManager’ is defined 錯誤。IdeaSpringMVC框架Bean
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'aaaa' availableSpringFrameworkBeanExceptionAI
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxxxx' iSpringFrameworkBeanException
- idea 報錯maven [ERROR] Maven execution terminated abnormally (exit code 1)IdeaMavenErrorORM
- 關於報錯Error creating bean with name 'xxxxx': Invocation of init method....ErrorBean
- MyBatis對映錯誤:There is no setter for property named xxxMyBatis
- spring與mybatis中注入了卻總提示no bean namedSpringMyBatisBean
- IDEA搭建和部署Maven專案IdeaMaven
- 啟動IDEA 報 failed to load jvm dll XXX 錯誤IdeaAIJVM
- yum安裝xxx包時出錯,提示No package xxx available.PackageAI
- 報錯xxxx of undefinedUndefined
- spring中bean.xml的http://www.springframework.org/schema/bean報錯SpringBeanXMLHTTPFramework
- No instances available for XXXAI
- idea ssm maven專案搭建筆記IdeaSSMMaven筆記
- Idea啟動SpringBoot報錯:程式包xxx 不存在IdeaSpring Boot
- TestNG+Maven+IDEA環境搭建+測試MavenIdea
- Linux:Python報錯:No module named MySQLdbLinuxPythonMySql
- IntelliJ IDEA編譯專案報錯 "xxx包不存在&qIntelliJIdea編譯