亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么老是找不到bean的名字啊?一直提示報錯

RT 就老是出現找不到bean的樣子

http://img1.sycdn.imooc.com//594aa3c0000132a905440249.jpg

http://img1.sycdn.imooc.com//594aa3c000019cbc07750264.jpg

http://img1.sycdn.imooc.com//594aa3c10001e30607480146.jpg

http://img1.sycdn.imooc.com//594aa3c1000100bd07150035.jpg


正在回答

1 回答

//這個是java文件
package?com.imooc.beanannotation;

import?org.springframework.stereotype.Component;

@Component
public?class?BeanAnnotation?{
	
	public?void?say(String?word){
		System.out.println("BeanAnnotation:"+word);
	}

}
//這個是配置文件
<?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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans?
			http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
			http://www.springframework.org/schema/context
			http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan?base-package="com.imooc.beanannotation">
</context:component-scan>		

</beans>
//這個是測試的文件,,我沒安裝老師那個方法,而是直接實例化
@Test
public?void?TestbeanAnnotation()?{
????????ApplicationContext?alc=new?ClassPathXmlApplicationContext("spring-beanannotation.xml");
	BeanAnnotation?bean=(BeanAnnotation)alc.getBean("beanAnnotation");
	bean.say("fuck");
		
	}


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

舉報

0/150
提交
取消
Spring入門篇
  • 參與學習       268802    人
  • 解答問題       1026    個

為您帶來IOC和AOP的基本概念及用法,為后續高級課程學習打下基礎

進入課程

為什么老是找不到bean的名字啊?一直提示報錯

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號