junit 测试 找不到beanname

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'studentBean' is defined

但是beanname 我已经定义过来

@Test

public void student()

{

ApplicationContext context = new ClassPathXmlApplicationContext(

"classpath*:applicationContext.xml");

Student obj = (Student) context.getBean("studentBean");

System.out.print(obj.getName());

}


<?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="studentBean" class="com.frank.springmvc.controller.Student">

        <!-- 在这里写额外的bean的配置和相关引用 -->

        <property name="name" value="hanyu"></property>

    </bean>


   


    <!-- 更多数据访问层的bean定义写在这里 -->


</beans


Ipython9
浏览 1352回答 1
1回答

qq_木偶_2

代码看起来没问题…会不会是配置文件名字不一致
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java