Основной класс обслуживания
@Service
public class MainService {
@Autowired
HouseRepository repository;
@Autowired
HouseDtoConverter converter;
public House addNewHouse(HouseDTO houseDTO) {
House h = converter.convert(houseDTO);
repository.save(h);
return h;``
}
public Iterable<House> getAllHouses() {
return repository.findAll();
}
}
Главный контроллер класса
@RestController // This means that this class is a Controller
@RequestMapping("/demo")
public class MainController {
@Autowired
MainService service;
@RequestMapping(value = "/add", method = RequestMethod.POST) // Map ONLY GET Requests
@ResponseBody
public House addNewHouse (@RequestBody HouseDTO houseDTO) {
return service.addNewHouse(houseDTO);
}
@RequestMapping(value="/all", method = RequestMethod.GET)
@ResponseBody
public Iterable<House> getAllHouses() {
// This returns a JSON or XML with the houses
return service.getAllHouses();
}
И трассировка стека:
Описание:
Полевой репозиторий в vikings.service.MainService требовал bean-компонент типа 'vikings.repository.HouseRepository', который не найден.
Точка впрыска имеет следующие аннотации:
- @ org.springframework.beans.factory.annotation.Autowired (обязательно = true)
Действие:
Рассмотрите возможность определения bean-компонента типа 'vikings.repository.HouseRepository' в вашей конфигурации.
Это мое SpringBootApplication
@Component
@SpringBootApplication
public class SpringBoot11Application {
public static void main(String[] args) {
SpringApplication.run(SpringBoot11Application.class, args);
}
}