關(guān)于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("我輸入的參數(shù)"));
}
@After
public void destory(){
ctx.destroy();
}
2016-10-21
是不是您的class名字寫錯了<剛開始我就是寫錯,運行不了>,
,我看了你的代碼,嘗試模仿運行,沒有錯啊。。。。。。
2016-10-21
我今天又看了下,發(fā)現(xiàn)有兩個問題。第一個是缺少一個jar包,二是getBean()當(dāng)中的大小寫錯誤了。非常感謝