Java 无法从web应用程序类路径加载Jadira Hibernate模块
我的web应用程序与Spring4.3/Hibernate5.1紧密集成 我的主Java 无法从web应用程序类路径加载Jadira Hibernate模块,java,spring,hibernate,Java,Spring,Hibernate,我的web应用程序与Spring4.3/Hibernate5.1紧密集成 我的主SessionFactory对象由一个扩展org.springframework.orm.hibernate5.LocalSessionFactoryBean的工厂处理 在LSFB的AfterPropertieSet上,Hibernate扫描模块和服务 当jadirajar文件出现在web类路径中时,我当前遇到以下错误 Caused by: java.util.ServiceConfigurationError: o
SessionFactory
对象由一个扩展org.springframework.orm.hibernate5.LocalSessionFactoryBean
的工厂处理
在LSFB的AfterPropertieSet
上,Hibernate扫描模块和服务
当jadirajar文件出现在web类路径中时,我当前遇到以下错误
Caused by: java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator not found
at java.util.ServiceLoader.fail(ServiceLoader.java:231)
at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:340)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:40)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:213)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.getMetadataSources(LocalSessionFactoryBean.java:364)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:399)
at com.acme.AnnotationSessionFactoryBean.afterPropertiesSet(AnnotationSessionFactoryBean.java:203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 35 more
我不明白为什么会这样。
为了加载Hibernate服务,有什么特别的事情要做吗?如何处理这些
ServiceConfigurationError
s?问题仅仅是由于Java版本不匹配和ServiceRegistry吞没了ClassNotFoundException
碰巧(我没有提到)Jadira6.x需要Java8/Hibernate5.2,但我使用的是Java7
CNFE
的根本原因是UnsupportedClassVersionError
,可以通过运行简单的main
尝试实例化所需的服务类来获得。在Java 8上运行应用程序有助于理解这一点(因为错误是API与HB 5.1不兼容),所以我不得不将Jadira降级为为什么需要将FactoryBean子类化?什么是如此特殊以至于您无法使用默认的Factorybean
?它使用自定义机制覆盖hibernate属性。您为什么需要它?您可以简单地将其外部化并设置属性。我建议不要使用您的子类(使用常规的LocalSessionFactoryBean
,看看问题是否仍然存在)。谢谢。不管怎样,我得到了问题的答案,这“只是”JVM版本不匹配,因为ServiceRegistry解决了根本问题。现在应用程序启动
try {
c = Class.forName(cn, false, loader);
} catch (ClassNotFoundException x) {
[OP: exception is swallowed]
fail(service,
"Provider " + cn + " not found");
}