Here is my spring boot multi module project structure.
[INFO] aggregator [pom]
[INFO] aggregatorservicecore [jar]
[INFO] aggregatorserviceapi [jar]
[INFO] aggregatorservicedata [jar]
[INFO] aggregatorservicesecurity [jar]
[INFO] aggregatorservicewebapp [jar]
Main class is present in aggregatorservicewebapp. Added all other child modules dependencies in webapp pom.xml, application started successfully.
I have used userRepository class in aggregatorserviceapi module which is declared in aggregatorservicedata module where i am getting issue No qualifying bean of type ‘com.wer.aggregatorservicedata.repository.UserRepository’ available: expected at least 1 bean which qualifies as autowire candidate.
UserRepository is properly annotated with @Repository. This interface package is included in componentscan in main class but still facing the issue.
Let me know what i am missing.
Below is my userrepository interface
@Repository
public interface UserRepository extends JpaRepository<UserDO,Long> {
Optional<UserDO> findByUserId(Long id);
}
This is used in userserviceimpl which is part of aggregatorserviceapi module which have REST API enabled. When calling REST API getting issue saying
‘com.wer.aggregatorservicedata.repository.UserRepository’ available: expected at least 1 bean which qualifies as autowire candidate.
@Service
@Scope("prototype")
public class UserServiceImpl implements UserService {
@Autowired(required = true)
private UserRepository userRepository;
@Override
public List<UserDTO> getAllUsers() {
List<UserDO> users = userRepository.findAll();
if (CollectionUtils.isEmpty(users)) {
throw new ResourceNotFoundException("No users.");
}
return users.stream().map(UserMapper::mapToUserDTO).collect(Collectors.toList());
}
Application started successfully but getting this issue when any class is interacting with userRepository dependency. Why is that?