我有一个正常工作的Grails 3应用程序,该应用程序通常以grails run-app
启动。当我尝试从IDE中使用Application.groovy
启动它时,我从GORM(下面的stacktrace)中得到了NullPointerException。
我的启动配置不正确吗?为什么行为不同?
这是IntelliJ生成的run-app命令,该命令有效:
"C:\Program Files\Java\jdk1e8.0_211\bin\java.exe" -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Dlogback.rootLogLevel=DEBUG -Djline.WindowsTerminal.directConsole=false -Dgrails.full.stacktrace=true -Dfile.encoding=UTF-8 -classpath C:\Users\rmorrise\AppData\Local\Temp\classpath634969171.jar org.grails.cli.GrailsCli run-app --plain-output
这是Application.groovy的调试命令,该命令不起作用:
"C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50806,suspend=y,server=n -Dlogback.rootLogLevel=DEBUG -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:C:\Users\rmorrise\.IntelliJIdea2019.1\system\groovyHotSwap\gragent.jar -javaagent:C:\Users\rmorrise\.IntelliJIdea2019.1\system\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath C:\Users\rmorrise\AppData\Local\Temp\classpath1916879940.jar elect.api.Application
我使用Application.groovy
启动的原因是可以使用YourKit Profiler代理启动。即使我不使用YourKit代理启动而只是使用“调试”命令,也会发生错误。
我正在使用的应用具有使用discriminator
映射的超级/子域类。子映射未能初始化,因为gorm @Entity批注在子代初始化时未应用于父实体。
堆栈跟踪如下:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
... 49 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSimpleId(GrailsDomainBinder.java:2512)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindIdentity(GrailsDomainBinder.java:1782)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRootPersistentClassCommonValues(GrailsDomainBinder.java:1738)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRoot(GrailsDomainBinder.java:1391)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.contribute(GrailsDomainBinder.java:165)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:275)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:276)
at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:39)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:23)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:204)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 51 common frames omitted
尝试的解决方法
我试图通过将以下JVM arg添加到运行应用程序启动配置中来附加YourKit分析器:
-agentpath:"C:\Program Files\YourKit Java Profiler 2019.8-b81\bin\win64\yjpagent.dll"
似乎没有将探查器应用于Grails JVM,因为启动CPU性能分析时我仍然遇到挂断。