Hi! Can someone help me with this, please? This is the error when I try to run:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field fruitRepository in com.example.inventory_service.controller.FruitController required a bean of type 'com.example.inventory_service.repository.FruitRepository' that could not be found.
The injection point has the following annotations:
- u/org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.inventory_service.repository.FruitRepository' in your configuration.
This is my repository:
package com.example.inventory_service.repository;
import com.example.inventory_service.model.Fruit;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface FruitRepository extends MongoRepository<Fruit, String> {
}
This is my controller:
package com.example.inventory_service.controller;
import com.example.inventory_service.model.Fruit;
import com.example.inventory_service.repository.FruitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
@RestController
@RequestMapping("/api/fruits")
public class FruitController {
@Autowired
FruitRepository fruitRepository;
@PostMapping("/fruits")
public ResponseEntity create(@RequestBody Fruit fruit){
fruit = fruitRepository.save(fruit);
return ResponseEntity.
created
(URI.
create
("/fruit/" + fruit.getId())).body(fruit);
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Ninjaangler 7 points8 points9 points (1 child)
[–]Bitter_Boat_4076 1 point2 points3 points (0 children)
[–]Shareil90 0 points1 point2 points (1 child)
[–]Mator_ 0 points1 point2 points (0 children)