Spring boot test “No qualifying bean of type available”

前端 未结 1 462
小鲜肉
小鲜肉 2021-02-05 03:02

I\'m quite a newbie to Spring boot, but here\'s the problem I\'m facing now:

// Application.java
public class Application {
  public static void main(String[] ar         


        
相关标签:
1条回答
  • 2021-02-05 03:42

    The test environment needs to know where your beans are defined, so you have to tell it the location.

    In your test class, add the @ContextConfiguration annotation:

    @RunWith(SpringRunner.class)
    @AutoConfigureTestDatabase(replace = Replace.NONE)
    @DataJpaTest
    @ContextConfiguration(classes = {YourBeans.class, MoreOfYourBeans.class})
    public class UserRepoTest {
    
      @Autowired
      private UserRepo userRepo = null;
    
      @Autowired
      private TestEntityManager entityManager = null;
    
    0 讨论(0)
提交回复
热议问题