작성
·
8.1K
1
안녕하세요 강사님!
강사님의 스프링과 jpa 강의를 듣고 프로젝트를 만드는 중인 학생입니다. 다름이 아니라 따로 좋아요 기능을 추가해서 학습한 내용을 바탕으로 제작 중인데
Error creating bean with name 'likeApiController' defined in file [/Users/gimnayeon/Desktop/GreenProject/GrinGreen/out/production/classes/com/grin/GrinGreen/api/LikeApiController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'likeService' defined in file [/Users/gimnayeon/Desktop/GreenProject/GrinGreen/out/production/classes/com/grin/GrinGreen/service/LikeService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'likeRepository' defined in com.grin.GrinGreen.repository.LikeRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional com.grin.GrinGreen.repository.LikeRepository.findBybusiness(com.grin.GrinGreen.domain.Member,com.grin.GrinGreen.domain.Business)! Reason: Failed to create query for method public abstract java.util.Optional com.grin.GrinGreen.repository.LikeRepository.findBybusiness(com.grin.GrinGreen.domain.Member,com.grin.GrinGreen.domain.Business)! At least 2 parameter(s) provided but only 1 parameter(s) present in query.; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.grin.GrinGreen.repository.LikeRepository.findBybusiness(com.grin.GrinGreen.domain.Member,com.grin.GrinGreen.domain.Business)! At least 2 parameter(s) provided but only 1 parameter(s) present in query.
라는 오류가 뜹니다.
LikeRepository
@Transactional(readOnly = true)
public interface LikeRepository extends JpaRepository<Like, Long> {
Optional<Integer> countBybusiness(Business business);
Optional<Like> findBybusiness(Member member, Business business);
}
business entity
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mail")
private Member member;
@OneToMany(mappedBy = "business", cascade = CascadeType.ALL)
Set<Like> likes = new HashSet<>();
member entity
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Business> business = new ArrayList<>();
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
Set<Like> likes = new HashSet<>();
like entity
@Id
@GeneratedValue
@Column(name = "like_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Member member;
@ManyToOne(fetch = FetchType.LAZY)
private Business business;
public Like(Business business, Member member) {
this.business = business;
this.member = member;
}
처음에는 jparepository에서 findBy 이후 대문자를 쓴 게 문제였나 싶어 수정을 했지만 아니었고
파라미터의 Id처럼 대문자로 쓰여진 게 문제인가 봤지만 해당 사항이 없었습니다..
아무리 강의를 돌려봐도 감이 안 잡히는 데 어디 부분의 문제일까요?ㅠㅠ
파라메터 값이 2개인데 1개만 받아졌다는 오류인 것도 같습니다....
답변 1
2
안녕하세요 해당 이름으로 해결 됐습니다. 감사합니다!!
혹시 메서드 이름 생성 규칙 같은 걸 볼 수 있는 사이트를 아실까요?ㅠ찾아봐도 잘 나오지 않아서요..