i just started my basic spring project and encountered some weird problem with beans and autowiring.
Field repository in app.user.UserModelImpl required a bean of type 'app.user.UserRepository' that could not be found.
UserModel.java
public interface UserModel {
List<User> findAll();
}
UserModelImpl.java
@Service
public class UserModelImpl implements UserModel {
@Autowired
private UserRepository repository;
@Override
public List<User> findAll() {
List<User> users = (List<User>) repository.findAll();
return users;
}
}
UserController.java
@RestController
public class UserController {
@Autowired
UserModel userModel;
@GetMapping("/")
public List findUsers(Model model)
{
System.out.println("HERE");
List<User> users = userModel.findAll();
return users;
}
}
UserRepository.java
@Component
public interface UserRepository extends JpaRepository<User, Long> {
}
Application.java
@SpringBootApplication(scanBasePackages={"app.user"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
All these files are in the same package called user. I'm totally new in this topic so I'm sorry if this is something really basic or trivial.