在使用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="ht