首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建名为JUnit @DataJpaTest JUnit错误

创建名为JUnit @DataJpaTest JUnit错误
EN

Stack Overflow用户
提问于 2022-11-30 13:00:02
回答 1查看 19关注 0票数 0

我正在尝试使用@DataJpaTest在存储库上进行测试,但是@Autowired不起作用--我已经尝试过使用@DataJPATest查找junit5的示例,但我没有找到它

我尝试添加其他依赖项,我使用了@SpringTest,它成功了,但我想使用@DataJpaTest

代码语言:javascript
复制
package com.projetoSpring.catalog.repositories;

import com.projetoSpring.catalog.model.Product;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.util.Optional;

@DataJpaTest
public class ProductRepositoryTests {

    @Autowired
    private ProductRepository repositorys;

    @Test
    public void deleteShouldDeleteObjectWhenIdExists() {

        long exintingId = 1L;

        repositorys.deleteById(exintingId);

        Optional<Product> result = repositorys.findById(1L);
        Assertions.assertFalse(result.isPresent());
    }
}
代码语言:javascript
复制
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.projetoSpring.catalog.repositories.ProductRepositoryTests': Unsatisfied dependency expressed through field 'repositorys'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.projetoSpring.catalog.repositories.ProductRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
EN

回答 1

Stack Overflow用户

发布于 2022-11-30 17:45:09

我设法解决了这个问题,我将spring更新到2.7.5版本,并验证了测试依赖关系没有正确下载,我重做了pom.xml,并且它工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74628206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档