Micronaut 数据 - 没有 [org.hibernate.SessionFactory] 类型的 bean
Micronaut Data - No bean of type [org.hibernate.SessionFactory]
首先要提的是 - 我已经准备好了一切 运行ning。我所做的唯一更改是在代码中添加了更多存储库。
然后我得到:
15:47:58.126 [pool-2-thread-4] ERROR
i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred:
Failed to inject value for parameter [sessionFactory] of class:
io.micronaut.transaction.hibernate5.HibernateTransactionManager
Message: No bean of type [org.hibernate.SessionFactory] exists for the
given qualifier: @Named('default'). Make sure the bean is not disabled
by bean requirements (enable trace logging for
'io.micronaut.context.condition' to check) and if the bean is enabled
then ensure the class is declared a bean and annotation processing is
enabled (for Java and Kotlin the 'micronaut-inject-java' dependency
should be configured as an annotation processor). Path Taken: new
HibernateTransactionManager([SessionFactory sessionFactory],DataSource
dataSource,Interceptor entityInterceptor)
io.micronaut.context.exceptions.DependencyInjectionException: Failed
to inject value for parameter [sessionFactory] of class:
io.micronaut.transaction.hibernate5.HibernateTransactionManager
我查了很多这方面的文章,但他们都提到了依赖关系。但我没有改变我的依赖。所以我开始调查。但是到现在都没有成功。
我仔细检查了我的 gradle.build
kapt 'io.micronaut.data:micronaut-data-processor:1.0.2'
implementation 'io.micronaut.data:micronaut-data-hibernate-jpa:1.0.2'
implementation 'io.micronaut.configuration:micronaut-jdbc-hikari'
runtime 'org.postgresql:postgresql:42.2.12'
testImplementation 'com.h2database:h2:1.4.200'
我也确保我使用了正确的版本,但单元测试不会 运行。
将 Gradle 6.4.1 与 micronaut 1.3.5 一起使用,显然将数据 1.0.2 与 jpa 一起使用。
有什么想法吗?
还激活了条件跟踪,但与会话工厂无关。
只是一些 spring 东西,但我不使用 spring,所以我认为还可以。
15:47:39.037 [Test worker] DEBUG i.m.context.condition.Condition - Bean [io.micronaut.jdbc.spring.$DataSourceTransactionManagerFactory$TransactionAwareDataSourceListener1Definition] will not be loaded due to failing conditions:
15:47:39.038 [Test worker] DEBUG i.m.context.condition.Condition - * Class [org.springframework.jdbc.datasource.DataSourceTransactionManager] is not present
任何想法..因为让我有点疯狂:D
奥利弗
我是 Kotlin 和 Micronaut 的新手,所以我不确定。但您的数据 class 以小写字母开头?
例如:
@Entity
data class dataBook (
@Id
@GeneratedValue
val id: Long
)
终于找到错误了:-)
data class DataX(
@Id
val id: String
) {
val yrefs
get() = _yrefs.toList()
@OneToMany(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH], orphanRemoval = true, fetch = FetchType.EAGER,
mappedBy = "yref") // < this was wrong must be xref
private val _yrefs= mutableListOf<DataY>()
}
data class DataY(
@Id
val id: String
) {
val zrefs
get() = _zrefs.toList()
@OneToMany(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH], orphanRemoval = true, fetch = FetchType.EAGER,
mappedBy = "zref")
private val _zrefs = mutableListOf<DataZ>()
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "x_ref_id")
var xref: DataX? = null
}
首先要提的是 - 我已经准备好了一切 运行ning。我所做的唯一更改是在代码中添加了更多存储库。
然后我得到:
15:47:58.126 [pool-2-thread-4] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Failed to inject value for parameter [sessionFactory] of class: io.micronaut.transaction.hibernate5.HibernateTransactionManager
Message: No bean of type [org.hibernate.SessionFactory] exists for the given qualifier: @Named('default'). Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor). Path Taken: new HibernateTransactionManager([SessionFactory sessionFactory],DataSource dataSource,Interceptor entityInterceptor) io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [sessionFactory] of class: io.micronaut.transaction.hibernate5.HibernateTransactionManager
我查了很多这方面的文章,但他们都提到了依赖关系。但我没有改变我的依赖。所以我开始调查。但是到现在都没有成功。
我仔细检查了我的 gradle.build
kapt 'io.micronaut.data:micronaut-data-processor:1.0.2'
implementation 'io.micronaut.data:micronaut-data-hibernate-jpa:1.0.2'
implementation 'io.micronaut.configuration:micronaut-jdbc-hikari'
runtime 'org.postgresql:postgresql:42.2.12'
testImplementation 'com.h2database:h2:1.4.200'
我也确保我使用了正确的版本,但单元测试不会 运行。
将 Gradle 6.4.1 与 micronaut 1.3.5 一起使用,显然将数据 1.0.2 与 jpa 一起使用。 有什么想法吗?
还激活了条件跟踪,但与会话工厂无关。 只是一些 spring 东西,但我不使用 spring,所以我认为还可以。
15:47:39.037 [Test worker] DEBUG i.m.context.condition.Condition - Bean [io.micronaut.jdbc.spring.$DataSourceTransactionManagerFactory$TransactionAwareDataSourceListener1Definition] will not be loaded due to failing conditions:
15:47:39.038 [Test worker] DEBUG i.m.context.condition.Condition - * Class [org.springframework.jdbc.datasource.DataSourceTransactionManager] is not present
任何想法..因为让我有点疯狂:D
奥利弗
我是 Kotlin 和 Micronaut 的新手,所以我不确定。但您的数据 class 以小写字母开头?
例如:
@Entity
data class dataBook (
@Id
@GeneratedValue
val id: Long
)
终于找到错误了:-)
data class DataX(
@Id
val id: String
) {
val yrefs
get() = _yrefs.toList()
@OneToMany(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH], orphanRemoval = true, fetch = FetchType.EAGER,
mappedBy = "yref") // < this was wrong must be xref
private val _yrefs= mutableListOf<DataY>()
}
data class DataY(
@Id
val id: String
) {
val zrefs
get() = _zrefs.toList()
@OneToMany(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH], orphanRemoval = true, fetch = FetchType.EAGER,
mappedBy = "zref")
private val _zrefs = mutableListOf<DataZ>()
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "x_ref_id")
var xref: DataX? = null
}