본문 바로가기

Error

[Error] Field repository in required a bean of type 'xxx' that could not be found.

# Error

Intellij에서 @Autowired를 통해서 CrudRpository를 상속받는 인터페이스를 사용할 때 아래와 같은 error가 발생한다.

Field repository in com.example.SpringDataJDBCSample.SpringDataJdbcSampleApplication required a bean of type 'xxx' that could not be found. 

 

# Solution

@EnableJdbcRespositories을 통해 JDBC Repository 를 활성화 할 수 있다.

@SpringBootApplication
@EnableJdbcRepositories(basePackages = { "path of target package ex) com.demo" })
public class SpringDataJdbcSampleApplication {
	public static void main(String[] args) {
		...
	}

	@Autowired
	Sample repository;
}

# Reference

https://docs.spring.io/spring-data/jdbc/docs/current/api/org/springframework/data/jdbc/repository/config/EnableJdbcRepositories.html

 

EnableJdbcRepositories (Spring Data Relational Parent 3.0.5 API)

repositoryImplementationPostfix String repositoryImplementationPostfix Returns the postfix to be used when looking up custom repository implementations. Defaults to Impl. So for a repository named PersonRepository the corresponding implementation class wi

docs.spring.io

 

'Error' 카테고리의 다른 글

[Error] Could not autowire. No beans of 'xxxx' type found.  (0) 2023.05.10