在我的项目中,我正在使用graphql-spring-java来实现graphql端点。我定义了graphql模式,并将所有实体放到kotlin中。问题是我的Kotlin中的方法签名之一不能正确解析,而其他所有方法签名都正确。这是逐字错误:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is com.coxautodev.graphql.tools.FieldResolverError: No method or field found with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:
ninja.familyhomestay.domain.Host.reservations()
ninja.familyhomestay.domain.Host.getReservations()
ninja.familyhomestay.domain.Host.reservations
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
... 105 common frames omitted
Caused by: com.coxautodev.graphql.tools.FieldResolverError: No method or field found with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:
ninja.familyhomestay.domain.Host.reservations()
ninja.familyhomestay.domain.Host.getReservations()
ninja.familyhomestay.domain.Host.reservations
at com.coxautodev.graphql.tools.FieldResolverScanner.missingFieldResolver(FieldResolverScanner.kt:51)
at com.coxautodev.graphql.tools.FieldResolverScanner.findFieldResolver(FieldResolverScanner.kt:42)
这是有问题的代码:
@Entity
@Table(name = "host")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "host")
class Host(
...
@OneToMany(mappedBy = "host")
var reservations: MutableSet<Reservation> = HashSet()
) : Serializable
@Entity
@Table(name = "reservation")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "reservation")
data class Reservation(
....
@ManyToOne
@JoinColumn(name = "host_id")
var host: Host? = null,
...) : Serializable {
companion object {
private const val serialVersionUID = 1L
}
}
很显然,代码没有错,所以我认为这是kotlin的问题。你怎么看?我正在使用Kotlin版本1.2.51
和idea 2018.2.eap
。