第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

為啥我的@Bean設(shè)置的init方法不能執(zhí)行,一直報(bào)類型轉(zhuǎn)換錯(cuò)誤

//這是我得到Bean容器的類

public class TestSpring {

public static void main(String[]args){

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("testSpring.xml");

/*TestProperty tp = (TestProperty) context.getBean("testPropertity");

TestProperty tp2 = (TestProperty) context.getBean("testPropertity");

System.out.println(tp);

System.out.println(tp == tp2);

Zhujie1 zj = (Zhujie1) context.getBean("zhujie1");

System.out.println(zj);*/

/*String tb = (String) context.getBean("name");

int pass = (int) context.getBean("pass");

System.out.println(tb);

System.out.println(pass);*/

Store tb2 = (Store) context.getBean("testBean2");

System.out.println(tb2.getClass());

context.close();

//這是我的store接口

public interface Store {}

//這是我的實(shí)現(xiàn)store的類

public class StringStore implements Store{

public void init(){

System.out.println("This is StringStore de init method");

}

public void destroy(){

System.out.println("This is StringStore's destroy method");

}

}

//這是在bean中設(shè)置init與destroy方法的類

@Configuration

public class TestBean2 {

@Bean(name="testBean2",initMethod="init",destroyMethod="destroy")

public Store method(){

return new StringStore();

}

}

//這是錯(cuò)誤

Exception in thread "main" java.lang.ClassCastException: com.test.zhujie2.TestBean2$$EnhancerBySpringCGLIB$$9eeb0c76 cannot be cast to com.test.zhujie2.Store

at com.test.Spring.TestSpring.main(TestSpring.java:24)


正在回答

1 回答

我不懂,但是我想問一下,不能被拋到zhujie2.Store中,代碼中的zhujie2在哪里


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為啥我的@Bean設(shè)置的init方法不能執(zhí)行,一直報(bào)類型轉(zhuǎn)換錯(cuò)誤

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號