https://github.com/daejoon/custom-repository
https://github.com/daejoon/custom-repository
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/daejoon/custom-repository
- Owner: daejoon
- Created: 2024-03-25T04:33:03.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T06:04:32.000Z (almost 2 years ago)
- Last Synced: 2024-09-09T06:52:34.012Z (almost 2 years ago)
- Language: Java
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Custom Repository
https://docs.spring.io/spring-data/jpa/reference/repositories/custom-implementations.html
Spring Data JPA와 Custom Repository를 Fragment 형식으로 복합적으로 사용할수 있다.
관습적으로 Custom Repository에 @Component, @Repository를 붙이는데 Bean을 선언하지 않아도
Spring Boot에서 Bean으로 등록해준다.
```java
class RepositoryBeanDefinitionBuilder {
...
private void potentiallyRegisterFragmentImplementation(RepositoryConfiguration> repositoryConfiguration,
RepositoryFragmentConfiguration fragmentConfiguration) {
String beanName = fragmentConfiguration.getImplementationBeanName();
// Already a bean configured?
if (registry.containsBeanDefinition(beanName)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Repository fragment implementation already registered: %s", beanName));
}
return;
}
fragmentConfiguration.getBeanDefinition().ifPresent(bd -> {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Registering repository fragment implementation: %s %s", beanName,
fragmentConfiguration.getClassName()));
}
bd.setSource(repositoryConfiguration.getSource());
registry.registerBeanDefinition(beanName, bd);
});
}
...
}
```
## Custom Repository
* @Repository @Component를 붙이지 않아도 자동으로 Bean로 생성된다.
* 명시적으로 빈으로 선언하면 중복되지 않고 선언되는 형식으로(이름 변경 가능) 빈이 생성된다.