spring学习bug记录:org.springframework.beans.factory.NoSuchBeanDefinitionException

    xiaoxiao2025-06-09  55

    Q:org.springframework.beans.factory.NoSuchBeanDefinitionException

    测试代码:

    public class test { @Test public void demo() { String xmlPath ="classpath*:/ApplicationContext.xml"; ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath); AccountServiceImpl accountService = applicationContext.getBean("accountService", AccountServiceImpl.class); accountService.transfer("rose","jack",1000); } }

    配置文件:

    <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"> <!-- datasource --> <bean id = "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" p:driverClass="com.mysql.jdbc.Driver" p:jdbcUrl="jdbc:mysql://localhost:3306/account" p:user="root" p:password="123"/> <!-- dao--> <bean id="accountDao" class="spring_tx_01.dao.AccountDaoImpl"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- service --> <bean id="accountService" class="spring_tx_01.service.AccountServiceImpl"> <property name="accountDao" ref="accountDao"></property> </bean> </beans>

    A:如何解决?

     

    最新回复(0)