I have UserRepository Interface that extends Jpa REpository Interface when Im trying to autowire it into a Servise or a Controller I recieve such an error -
Parameter 0 of constructor in com.example.boottestfinal.UserHelper required a bean of type 'com.example.boottestfinal.UserRepository' that could not be found.
my project structure just in case - click
UserRepository -
package com.example.boottestfinal;
import com.example.boottestfinal.enities.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
}
Service -
package com.example.boottestfinal;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.boottestfinal.enities.User;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserHelper {
private final UserRepository userRepository;
@Autowired
public UserHelper(UserRepository userRepository) {
this.userRepository = userRepository;
}
public void addUser(User user){
userRepository.save(user);
}
public List<User> findAllUsers(){
return userRepository.findAll();
}
}
Entity -
package com.example.boottestfinal.enities;
import jakarta.persistence.*;
import lombok.*;
import java.io.Serializable;
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@ToString
@Entity
@Table(name = "usertable")
public class User implements Serializable {
@Id
// @SequenceGenerator(name = "userSequence", sequenceName = "userSequence", allocationSize = 1)
// @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userSequence")
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
int age;
String name;
public User(int age, String name) {
this.age = age;
this.name = name;
}
}
If its not enough for an answear I can provide with more Information I am new to Spring Boot, hope someone helps!