CrudRepository通过字段folioRepository

时间:2016-09-02 11:30:20

标签: spring junit

我收到的错误由以下原因引起:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为' getFolioService'的错误:通过字段< folioRepository表达的不满意的依赖关系':没有资格类型为[abcrepository.FolioRepository]的bean 我正在为我的服务运行Junit测试用例,它将文件保存在couchbase中。

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
public class FolioServiceTest {

    @Autowired
    private FolioService folioService;

    @Test
    public void testAddFolioTransaction() {
        Folios folios  = new Folios();
        folios.setUiid("user123");
        List<Order> orders = new ArrayList<Order>();
        Order order = new Order();
        order.set__type("type1");
        order.set__version("version1");
        order.setCreatedDate("09/02/2016");
        order.setCreatedUser("test user");
        OrderPayload orderPayload = new OrderPayload();
        orderPayload.set__type("type payload type");
        orderPayload.set__version("version payload type");
        order.setOrderPayload(orderPayload);
        orders.add(order);
        folios.getOrder().addAll(orders);
        boolean flag= folioService.addFolioTransaction(folios);
        assertTrue(flag == true);
    }

    @Configuration
    public class AppConfig {

        @Bean
        public FolioService getFolioService() {
            return new FolioService();
        }
    }
}

@服务 公共类FolioService {

private final static Logger LOGGER = LoggerFactory.getLogger(FolioService.class);

@Autowired
FolioRepository folioRepository;


/**
 * Method will save the folio to the couchbase
 * 
 * @param folios
 */
public boolean addFolioTransaction(Folios folios){
    LOGGER.debug("Adding transaction details to folio.");
    Folios newFolio = folioRepository.save(folios);
    if (newFolio != null) {
        return true;
    }
    return false;
}

public Folios getFolioDetailsByUiid(String uiid){
    LOGGER.debug("Get folio details by uiid.");
    Folios folios = folioRepository.findOne(uiid);      
    return folios;
}

}

@Repository 公共接口FolioRepository扩展了CrudRepository {

}

0 个答案:

没有答案