带有纯 Hibernate JPA 的 Micronaut 1.0.RC1 在启动时失败
Micronaut 1.0.RC1 with plain Hibernate JPA fails at startup
使用
创建空白 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 创建该数据库 table 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'
这是因为您在运行时类路径中同时拥有 jdbc-tomcat
和 jdbc-hikari
。这导致使用相同的名称限定符创建 2 个数据源。这是 CLI 中的一个错误,导致项目以这种方式创建
我已经为你提交了一个问题https://github.com/micronaut-projects/micronaut-core/issues/681
使用
创建空白 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 创建该数据库 table 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'
这是因为您在运行时类路径中同时拥有 jdbc-tomcat
和 jdbc-hikari
。这导致使用相同的名称限定符创建 2 个数据源。这是 CLI 中的一个错误,导致项目以这种方式创建
我已经为你提交了一个问题https://github.com/micronaut-projects/micronaut-core/issues/681