Tag: spring annotations

用于Kotlin方法的Java注释的getAnnotation返回null

说,我有以下界面: interface AppRepository : GraphRepository<App> { @Query("""MATCH (a:App) RETURN a""") fun findAll(): List<App> } 在测试中,我想检查查询字符串的具体情况,因此我做 open class AppRepositoryTest { lateinit @Autowired var appRepository: AppRepository @Test open fun checkQuery() { val productionMethod = appRepository.javaClass.getDeclaredMethod("findAll") val productionQuery = productionMethod!!.getAnnotation(Query::class.java) //demo test assertThat(productionQuery!!.value).isNotEmpty() //KotlinNPE } } 由于我不理解的原因, productionQuery是null 。 我已经双重检查了测试类中导入的Query的类型和存储库中的Query是相同的。 因此,在这种情况下为什么productionQuery null ?