1. 程式人生 > >java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nat

java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nat

我做的是Spring 事務的傳播行為的時候報瞭如下錯誤


java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [cn.com.day04.BookShopListImpl] is defined: expected single bean but found 0:


 


這是因為存在著兩個類的型別都是一樣的,無法知道到底指定的是哪個,所以需要重新命名

我的情況是一個介面類BookShopList,一個實現類BookShopListImpl,

我在bean裡面呼叫BookShopListImpl類的時候

錯誤程式碼如下:

private static BookShopListImpl bookShop=null;
    static {
        ioc = new ClassPathXmlApplicationContext("bean-jdbc.xml");
        bookShop=ioc.getBean(BookShopListImpl.class);
    }

正確的程式碼

private static BookShopList bookShop=null;
    static {
        ioc = new ClassPathXmlApplicationContext("bean-jdbc.xml");
        bookShop=ioc.getBean(BookShopList.class);
    }


但是我就是覺得奇怪,介面的類是BookShopList

型別,我的實現類的類名是BookShopListImpl ,難道我這個實現類是BookShopList型別不是BookShopListImpl 型別了麼?

有知道的希望可以留言評論