【1】java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
解决方式:忘记写里面的内容了
【2】 org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.hy.ioc.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.hy.ioc.User.<init>()
只显示这个错误的主要的语句:解决方式—需要实体类里拥有无参构造 这样子Bean才能够实例化
【3】Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'book' defined in class path resource [bean1.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'bookname' of bean class [com.hy.property.Book]: Bean property 'bookname' is not writable or has an invalid setter method. Did you mean 'bookName'?
set方法的名字一定要规范来写、
【4】这是一个来自jdbc的错误 自从mysql更新到了8.0.18的版本时候 JDBC的Driver不能使用原来的“com.mysql.jdbc.Driver”了,而是要改成“com.mysql.cj.jdbc.Driver”
报错如下:
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
【5】Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'bookservice' is defined
这个错误显示的是 bookservice未定义 其实也就是在ApplicationContext里获取对象是 获取错了XML文件
这里的bean1.xml 改成 bean2.xml
【6】org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'book' defined in class path resource [bean3.xml]:
其实就是方法名写错了 一定得要注意方法名的对应