APPLICATION FAILED TO START
Description:
Field repository in br.com.alura.forum.controller.TopicController required a bean of type 'br.com.alura.repository.TopicRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'br.com.alura.repository.TopicRepository' in your configuration.
Interface TopicRepository.
package br.com.alura.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import br.com.alura.model.Topic;
public interface TopicRepository extends JpaRepository<Topic, Long> {
}
Definição da classe TopicController.
package br.com.alura.forum.controller;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import br.com.alura.forum.controller.dto.TopicDto;
import br.com.alura.model.Topic;
import br.com.alura.repository.TopicRepository;
@RestController
@RequestMapping("/topic")
public class TopicController {
@Autowired
private TopicRepository repository;
public TopicController() {
// construtor padrão
}
@GetMapping
public List<TopicDto> list() {
List<Topic> topics = repository.findAll();
return topics.stream().map(TopicDto::new).collect(Collectors.toList());
}
}