将 Hibernate 4 与 Grails 3.2.4 一起使用时启动时出现 NullPointerException

NullPointerException on start up when using Hibernate 4 with Grails 3.2.4

我按照 Grails 3.2 documentation 中的说明从休眠 5(默认)切换到休眠 4。但是,现在我的应用程序无法启动。我在启动时收到如下所示的异常。

01/12/2017 11:52:55 PST ERROR main SpringApplication:839 - Application startup failed
java.lang.NullPointerException: null
    at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1337)
    at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1197)
    at java.beans.Introspector.getBeanInfo(Introspector.java:426)
    at java.beans.Introspector.getBeanInfo(Introspector.java:173)
    at java.beans.Introspector.getBeanInfo(Introspector.java:260)
    at java.beans.Introspector.<init>(Introspector.java:407)
    at java.beans.Introspector.getBeanInfo(Introspector.java:173)
    at groovy.lang.MetaClassImpl.run(MetaClassImpl.java:3290)
    at java.security.AccessController.doPrivileged(Native Method)
    at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3288)
    at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3265)
    at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:254)
    at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:285)
    at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.<init>(ClassMetaClassGetPropertySite.java:38)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.createClassMetaClassGetPropertySite(AbstractCallSite.java:373)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.createGetPropertySite(AbstractCallSite.java:325)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.acceptGetProperty(AbstractCallSite.java:312)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
    at org.grails.plugins.databasemigration.DatabaseMigrationGrailsPlugin.configureLiquibase(DatabaseMigrationGrailsPlugin.groovy:96)
    at org.grails.plugins.databasemigration.DatabaseMigrationGrailsPlugin.doWithSpring(DatabaseMigrationGrailsPlugin.groovy:55)
    at org.grails.plugins.DefaultGrailsPlugin.doWithRuntimeConfiguration(DefaultGrailsPlugin.java:555)
    at org.grails.plugins.AbstractGrailsPluginManager.doRuntimeConfiguration(AbstractGrailsPluginManager.java:167)
    at grails.boot.config.GrailsApplicationPostProcessor.postProcessBeanDefinitionRegistry(GrailsApplicationPostProcessor.groovy:171)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)  

一些快速的谷歌搜索似乎暗示这个错误是由项目的依赖项不匹配引起的。然而,Grails 3.2 文档只提到添加 hibernate 4 依赖项,但没有更改任何其他依赖项。有谁知道这里发生了什么以及如何解决它?

首先使用 -

刷新依赖项
grails clean --refresh-dependencies

使用此命令构建依赖关系报告 -

grails dependency-report

确认应用程序正在使用 hibernate 4 依赖项。查看它的任何插件是否正在使用 hibernate 5 依赖项。如果是这样,请将其从相应插件的 build.gradle 文件中排除。