Всякий раз, когда я пытаюсь автоматически связать собственный репозиторий, реализующий репозиторий JPA в моем классе контроллера, он не может этого сделать и выдает ошибку «no bean def found found», тогда как если я делаю то же самое с любым классом обслуживания, то он работает нормально. Может кто-нибудь объяснить мне, почему это так?
Spring Boot
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-02-15 13:01:50.169 ERROR 16304 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field customerRepo in Controllers.MainController required a bean of type 'Repository.CustomerRepo' 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 'Repository.CustomerRepo' in your configuration.
```
@SpringBootApplication
@ComponentScan(basePackages = "Controllers")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
``````````````````
@RestController
@RequestMapping("/")
public class MainController {
@Autowired
private CustomerRepo customerRepo;
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String homePage() {
Customer testCustomer = new Customer();
testCustomer.setFirstName("csdcsdccs");
testCustomer.setLastName("csdcsdccs");
testCustomer.setMiddleName("csdcsdccs");
testCustomer.setAddressLine("csdcsdccs");
testCustomer.setCountry("csdcsdccs");
testCustomer.setPincode(713201);
testCustomer.setState("csdcsdccs");
testCustomer.setDateOfBirth(new Date(2019, 5, 13));
customerRepo.save(testCustomer);
return "inserted";
}
}
`````````````
@Repository
public interface CustomerRepo extends CrudRepository<Customer, Long> {
}
``````````````````````````