Я изучаю весеннюю загрузку с JPA, и у меня возникла проблема при запуске моего приложения. Может ли кто-нибудь помочь мне решить эту проблему? Ошибка -
Description: Field userRepo in com.example.demo.controller.DemoController required a bean of type 'com.example.demo.repo.UserRepo' 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 'com.example.demo.repo.UserRepo' in your configuration.
Контроллер
public class DemoController {
private static final String CLASS_NAME = DemoController.class.getName();
@Autowired
private UserRepo userRepo;
@Autowired
private UserServiceImpl userService;
@PostMapping(value = "/hello", consumes = "application/json", produces = "application/json")
public String createUser(@RequestBody User user) {
long count = userRepo.count();
return "Done";
}
}
хранилище
@Repository
public interface UserRepo extends JpaRepository<User, Integer> {
}
Класс приложения
@SpringBootApplication
@ComponentScan("com.example.demo*")
@EnableJpaRepositories(basePackages = {"com.example.demo*"})
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Структура проекта
Я аннотировал репозиторий с помощью @Repository и использовал @Autowiredна контроллере. Где я делаю не так?