为了账号安全,请及时绑定邮箱和手机立即绑定

关于Junit显示名字找不到

<?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="OneInterface" class="com.imooc.ioc.interfaces.OneInterfaceImpl"></bean>

 </beans>

显示 No bean named “OneInterface” is defined。  请问是为什么?

 private ClassPathXmlApplicationContext ctx;

 

@Before

public void init(){

ctx = new ClassPathXmlApplicationContext("classpath*:spring-ioc.xml");//如果在src目录下则是classpath*:。如果在其他路径则在classpath*:加入路径名称如spring/

ctx.start();

}

@Test

public void test(){

OneInterface oif = (OneInterface)ctx.getBean("OneInterface");//这里为什么会显示找不到???????

System.out.println(oif.say("我输入的参数"));

}

@After

public void destory(){

ctx.destroy();

}


正在回答

2 回答

是不是您的class名字写错了<刚开始我就是写错,运行不了>,http://img1.sycdn.imooc.com//580978390001553b12890567.jpg,我看了你的代码,尝试模仿运行,没有错啊。。。。。。

0 回复 有任何疑惑可以回复我~

我今天又看了下,发现有两个问题。第一个是缺少一个jar包,二是getBean()当中的大小写错误了。非常感谢

0 回复 有任何疑惑可以回复我~
#1

老季

你少了什么包,我也一直抱着错
2017-02-21 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Spring入门篇
  • 参与学习       268771    人
  • 解答问题       963    个

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

进入课程

关于Junit显示名字找不到

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信