Hy everybody
I have this simplified version of my trouble. I´m trying to run my application but it fails as Repository is not beign recognized to be injected. I already tried to annotate Repository as Service and to add the repository package to be scanned, but none works. Can someone help me?
I get an exception
Description:
Field topicRepository in br.com.alura.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.
Controller/Service
@Autowired
private TopicRepository topicRepository;
@GetMapping(value = "/api/topics", produces = MediaType.APPLICATION_JSON_VALUE)
public Page<TopicBriefOutputDto> listTopics(TopicSearchInputDto topicSearch, @PageableDefault(sort="creationInstant", direction=Sort.Direction.DESC) Pageable pageRequest) {
Specification<Topic> topicSearchSpecification = topicSearch.build();
Page<Topic> topics = this.topicRepository.findAll(topicSearchSpecification, pageRequest);
return TopicBriefOutputDto.listFromTopics(topics);
}
Start
@SpringBootApplication
@Configuration
@ComponentScan(basePackages ={"br.com.alura.controller"})
@EntityScan
@EnableAutoConfiguration
@EnableJpaRepositories
@EnableSpringDataWebSupport
public class ForumApplication {
public static void main(String[] args) {
SpringApplication.run(ForumApplication.class, args);
}
}
Repository
public interface TopicRepository extends Repository<Topic, Long>, JpaSpecificationExecutor<Topic> {
}