使用创建空白 micronaut 应用程序时
mn create-app sillynaut --profile service \
--features java,spock,jdbc-hikari,hibernate-jpa,jib
然后添加一个实体Person
。
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false)
private Long id;
@Column
private String surname;
@Column
private String firstName;
// getter/setter omitted
}
然后,当我启动应用程序时,Micronaut 成功指示 Hibernate 创建该数据库表person
,但随后失败并出现以下错误:
20:28:55.470 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [org.hibernate.SessionFactory]: null
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [org.hibernate.SessionFactory]: null
at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1002)
at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:190)
at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:1912)
at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:151)
at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:138)
at io.micronaut.runtime.Micronaut.start(Micronaut.java:67)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:271)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:257)
at sillynaut.Application.main(Application.java:8)
Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [org.hibernate.SessionFactory]: null
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1279)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1780)
at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:1466)
at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1000)
... 8 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.hibernate.type.spi.TypeConfiguration.scope(TypeConfiguration.java:149)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at io.micronaut.configuration.hibernate.jpa.EntityManagerFactoryBean.hibernateSessionFactory(EntityManagerFactoryBean.java:177)
at io.micronaut.configuration.hibernate.jpa.$EntityManagerFactoryBean$HibernateSessionFactoryDefinition.build(Unknown Source)
at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:197)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1263)
... 11 common frames omitted
对我来说,这似乎是一个错误,还是我错过了什么?
---- 请在build.gradle
下面找到我的
plugins {
id "io.spring.dependency-management" version "1.0.6.RELEASE"
id "com.github.johnrengelman.shadow" version "4.0.0"
id "net.ltgt.apt-eclipse" version "0.18"
id "net.ltgt.apt-idea" version "0.18"
id "com.google.cloud.tools.jib" version "0.9.9"
}
apply plugin:"application"
apply plugin:"java"
apply plugin:"groovy"
version "0.1"
group "sillynaut"
repositories {
mavenLocal()
mavenCentral()
maven { url "https://jcenter.bintray.com" }
}
dependencyManagement {
imports {
mavenBom 'io.micronaut:bom:1.0.0.RC1'
}
}
dependencies {
annotationProcessor "io.micronaut:inject-java"
annotationProcessor "io.micronaut:validation"
annotationProcessor "javax.persistence:javax.persistence-api:2.2"
implementation "io.micronaut:http-client"
compile "io.micronaut:inject"
implementation "io.micronaut:validation"
implementation "io.micronaut:runtime"
implementation "io.micronaut.configuration:jdbc-hikari"
implementation "io.micronaut.configuration:hibernate-jpa"
implementation "io.micronaut:http-server-netty"
implementation "javax.annotation:javax.annotation-api:1.3.2"
compileOnly "io.micronaut:inject-java"
runtimeOnly "ch.qos.logback:logback-classic:1.2.3"
runtimeOnly "io.micronaut.configuration:jdbc-tomcat"
testImplementation("org.spockframework:spock-core:1.2-groovy-2.4") {
exclude group: "org.codehaus.groovy", module: "groovy-all"
}
testImplementation "io.micronaut:inject-groovy"
testImplementation "junit:junit:4.12"
testImplementation "io.micronaut:inject-java"
testImplementation "org.hamcrest:hamcrest-all:1.3"
runtime 'org.mariadb.jdbc:mariadb-java-client:2.2.5'
}
shadowJar {
mergeServiceFiles()
}
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1')
mainClassName = "sillynaut.Application"
compileJava.options.compilerArgs += '-parameters'
compileTestJava.options.compilerArgs += '-parameters'
jib.to.image = 'gcr.io/sillynaut/jib-image'