就一个实体类,一个测试类
@Data
@Entity
@Table(name="hanma_seller")
@Proxy(lazy = false)
public class SellerInfo {
@Id
private String sellerId;
private String username;
private String password;
private String openid;
}
```java
@RunWith(SpringRunner.class)
@SpringBootTest
public class SellerInfoTest {
@Autowired
private SellerInfoRepository repository;
@Test
public void saveTest(){
SellerInfo sellerInfo=new SellerInfo();
sellerInfo.setSellerId(KeyUtil.getUniqueKey());
sellerInfo.setUsername("admin");
sellerInfo.setPassword("admin");
sellerInfo.setOpenid("abcd");
SellerInfo result=repository.save(sellerInfo);
Assert.assertNotNull(result);
}
@Test
public void findTest(){
SellerInfo result=repository.findByOpenid("abcd");
Assert.assertEquals("abcd",result.getOpenid());
}
}
报错:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.jingdong.SellerInfoTest': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.jingdong.repository.SellerInfoRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}