首页 > 解决方案 > Spring Boot 中异常的传播

问题描述

Spring Boot 是否以一种或另一种方式包装/隐藏/封装异常?

产生异常时会出现一些奇怪的行为。例如,在 Spring Boot + JPA 项目中,如果我注释掉 @Entity 注释:

@Table(name = "XXX")
//@Entity
public class Contract
{
...
}

我得到以下异常(警告):

2018-12-10 19:09:33.153 DEBUG DESKTOP-48HHHCD --- [ost-startStop-1] o.h.c.CollectionSecondPass               : Second pass for collection: cp.dmo.bean.ContribuablePar.listeContratMensu
2018-12-10 19:09:33.153 DEBUG DESKTOP-48HHHCD --- [ost-startStop-1] o.h.c.a.CollectionBinder                 : Binding a collection of element: cp.dmo.bean.ContribuablePar.listeContratMensu
2018-12-10 19:09:33.154  WARN DESKTOP-48HHHCD --- [ost-startStop-1] o.s.b.f.s.DefaultListableBeanFactory     : Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testpopulationserviceso' defined in file [C:\Users\celfer\AppData\Local\Temp\1-dmo\WEB-INF\classes\conf\application\applicationContext-service.xml]: Cannot resolve reference to bean 'testpopulationserviceimpl' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testpopulationserviceimpl' defined in file [C:\Users\celfer\AppData\Local\Temp\1-dmo\WEB-INF\classes\conf\application\applicationContext-service.xml]: Cannot resolve reference to bean 'testpopulationdao' while setting bean property 'testpopulationdao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testpopulationdao' defined in file [C:\Users\celfer\AppData\Local\Temp\1-dmo\WEB-INF\classes\conf\application\applicationContext-dao.xml]: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jar:file:/C:/Users/celfer/AppData/Local/Temp/1-dmo/WEB-INF/lib/lombok-jpa-24.0.6-SNAPSHOT.jar!/conf/applicationContext-datasources-jpa2.xml]: Cannot resolve reference to bean 'entityManager' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManager' defined in URL [jar:file:/C:/Users/celfer/AppData/Local/Temp/1-dmo/WEB-INF/lib/lombok-jpa-24.0.6-SNAPSHOT.jar!/conf/applicationContext-datasources-jpa2.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2018-12-10 19:09:33.155 DEBUG DESKTOP-48HHHCD --- [ost-  startStop-1] o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean 'lecturepersonneso'

所以异常表示应用程序无法构建 Hibernate SessionFactory,但它没有准确指出问题出在哪里。

有什么线索吗?谢谢

标签: javaspringspring-boot

解决方案


推荐阅读