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資料夾圖示會變
相關文章
- spring中No bean named xxx available錯誤SpringBeanAI
- No Bean named 'Xxx' available 異常報錯BeanAI
- No bean named ''XXX“ availableBeanAI
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- Spring:錯誤No bean named 'xxxxxxx' availableSpringBeanAI
- spring-mybatis整合:NoSuchBeanDefinitionException: No bean named 'xxx.class' availableSpringMyBatisBeanExceptionAI
- Spring中出現:No bean named 'XXX' available問題解決SpringBeanAI
- SpringBoot 學習之 No bean named ‘xxx’ availableSpring BootBeanAI
- 記一次idea構建springmvc報錯:No bean named 'cacheManager' availableIdeaSpringMVCBeanAI
- No bean named BookServiceImpl availableBeanAI
- 報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx'is definedSpringFrameworkBeanException
- Caused by:.NoSuchBeanDefinitionException: No bean named 'userInfoServiceImpl' availableBeanExceptionAI
- 使用@Service註解出現No bean named 'xxxx' available]錯誤BeanAI
- No bean named 'xxx' is defined錯誤,原因及解決方案Bean
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'aaaa' availableSpringFrameworkBeanExceptionAI
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- spring getBean(String) No bean named '' is definedSpringBean
- 使用Idea構建springmvc框架,出現no bean named ‘cacheManager’ is defined 錯誤。IdeaSpringMVC框架Bean
- No instances available for XXXAI
- idea 報錯maven [ERROR] Maven execution terminated abnormally (exit code 1)IdeaMavenErrorORM
- 啟動IDEA 報 failed to load jvm dll XXX 錯誤IdeaAIJVM
- 程式碼改造引發的NoSuchBeanDefinitionException:no bean named 'XXXX' available問題解決方案BeanExceptionAI
- Idea啟動SpringBoot報錯:程式包xxx 不存在IdeaSpring Boot
- IntelliJ IDEA編譯專案報錯 "xxx包不存在&qIntelliJIdea編譯
- IDEA搭建和部署Maven專案IdeaMaven
- spring中bean.xml的http://www.springframework.org/schema/bean報錯SpringBeanXMLHTTPFramework
- idea ssm maven專案搭建筆記IdeaSSMMaven筆記
- Linux:Python報錯:No module named MySQLdbLinuxPythonMySql
- Maven建立SSM專案 啟動時報錯Mapped Statements collection does not contain value for xxxMavenSSMAPPAI
- TestNG+Maven+IDEA環境搭建+測試MavenIdea
- IDEA社群版搭建Spring工程(03-Spring MVC搭建)IdeaSpringMVC
- Spring注入bean報錯 Error creating bean with name的網上找不到的解決方案SpringBeanError
- 搭建 docker registry 私有倉庫並解決報錯Get https://xxx.xxx.xxx.xxx:5000/v1/_ping: http: server gave HTTP respDockerHTTPServer
- The bean ‘xxx‘, defined in class path resource , ......Bean
- beego報錯 table name: `xxx` not existsGo
- 【maven】Maven報錯 zip END header not foundMavenHeader
- 使用PyCharm時顯示的 No module named ‘xxx’PyCharm
- IntelliJ IDEA 建立Spring+SpringMVC+mybatis+maven專案IntelliJIdeaSpringMVCMyBatisMaven