본문 바로가기

SpringBoot

repository @AutoWired injection 에러

Field accountRepository in org.hch.auth.service.UserServiceImpl required a bean of type 'org.hch.auth.repository.AccountRepository' 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 'org.hch.auth.repository.AccountRepository' in your configuration.

 

 

@Repository
public interface AccountRepository extends JpaRepository<Account, Long> {

}

 

@Service
public class UserServiceImpl implements UserService {
@Autowired
private AccountRepository accountRepository;

 

}

 

@AutoWired 관련 의존성 에러가 났다.

검색을 해보니 AccountRepository는 userServiceImpl의 의존객체이며 @Autowired를 붙여 생성자를 생성하려면 오류가 생긴다.

 

해결방법--> @Autowired에 required 속성값을 추가

 

@Autowired(required = false)은 의존성을 'Optional'로 설정