Я получаю org.springframework.beans.factory.UnsatisfiedDependencyException, когда я вызываю SaleRestService в ProductRestService, как показано в коде ниже.
Как я могу сделать это правильно?
@RestController
@CrossOrigin("*")
public class ProductRestService {
@Autowired
private ProductRepository productRepository;
@Autowired
public SaleRestService saleRestService ;
@RequestMapping(value="/productQuatityMinusOne", method=RequestMethod.GET)
@ResponseBody
public void ProductQuatityMinusOne(@RequestParam(name="id") Long id){
Product p = productRepository.findProductById(id);
double salePrice = p.getPrice();
Date now = new java.util.Date();
Sale s = new Sale(id,salePrice,now);
saleRestService .saveOneSale(s);
p.setId(id);
int q = p.getQuantity()-1;
p.setQuantity(q);
productRepository.save(p);
}
}
@RestController
@CrossOrigin("*")
public class SaleRestService {
@Autowired
private SaleRepository saleRepository;
//Save one sale
@RequestMapping(value="/saveOneSale", method=RequestMethod.POST)
@ResponseBody
public Sale saveOneSale(@RequestBody Sale s){
return saleRepository.save(s);
}
}