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

版权声明:博客知识产权来源命运的信徒,切勿侵权 https://blog.csdn.net/qq_37591637/article/details/85210605

我做的是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 类型了么?

有知道的希望可以留言评论

猜你喜欢

转载自blog.csdn.net/qq_37591637/article/details/85210605
今日推荐