Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Kotlintest中的Autowire弹簧检测仪管理器不工作_Spring Boot_Kotlintest - Fatal编程技术网

Spring boot Kotlintest中的Autowire弹簧检测仪管理器不工作

Spring boot Kotlintest中的Autowire弹簧检测仪管理器不工作,spring-boot,kotlintest,Spring Boot,Kotlintest,作为学习经验,我正在尝试将SpringBoot的kotlin教程()中描述的测试从JUnit5移植到KotlinTest 在用@DataJpaTest注释的存储库测试中,我成功地自动连接了我的JPA存储库。但是autowiring Spring Boot的TestEntityManager不起作用,因为我得到java.lang.IllegalStateException:当我尝试在测试中使用它时,找不到事务性EntityManager 除了@DataJpaTest,我还尝试添加@Transact

作为学习经验,我正在尝试将SpringBoot的kotlin教程()中描述的测试从JUnit5移植到KotlinTest

在用
@DataJpaTest
注释的存储库测试中,我成功地自动连接了我的JPA存储库。但是autowiring Spring Boot的
TestEntityManager
不起作用,因为我得到
java.lang.IllegalStateException:当我尝试在测试中使用它时,找不到事务性EntityManager

除了
@DataJpaTest
,我还尝试添加
@Transactional
,但运气不佳

使用JUnit5运行测试时,使用entityManager持久化实体可以很好地工作

@DataJpaTest
class RepositoriesTests @Autowired constructor(
        val entityManager: TestEntityManager,
        val userRepository: UserRepository,
        val articleRepository: ArticleRepository) {

    @Test
    fun `When findByIdOrNull then return article`() {
        val juergen = User(login = "springjuergen", firstname = "Juergen", lastname = "Hoeller")
        entityManager.persist(juergen) <--- OK
@DataJpaTest
类RepositoriesTests@Autowired构造函数(
val entityManager:TestEntityManager,
val userRepository:userRepository,
val articleRepository:articleRepository){
@试验
fun`findByIdOrNull时返回文章`(){
val juergen=User(login=“springjuergen”,firstname=“juergen”,lastname=“Hoeller”)

entityManager.persist(juergen)这似乎是KotlinTest与Spring集成的一个bug。对于它,以及。现在,您可以做的是复制PR中的内容并使用该侦听器,直到我们能够正确发布错误修复。此问题可能提供一些线索:
@DataJpaTest
class RepositoriesTests @Autowired constructor(
        val entityManager: TestEntityManager,
        val userRepository: UserRepository,
        val articleRepository: ArticleRepository) : StringSpec() {

    init {

        "When findByIdOrNull then return article" {
            val juergen = User(login = "springjuergen", firstname = "Juergen", lastname = "Hoeller")
            entityManager.persist(juergen) <--- FAIL