1616package org .springframework .data .jdbc .repository .support ;
1717
1818import java .io .Serializable ;
19-
2019import org .springframework .beans .factory .BeanFactory ;
21- import org .springframework .beans .factory .annotation .Autowired ;
2220import org .springframework .context .ApplicationEventPublisher ;
2321import org .springframework .context .ApplicationEventPublisherAware ;
2422import org .springframework .data .jdbc .core .convert .DataAccessStrategy ;
4947 * @author Hebert Coelho
5048 * @author Chirag Tailor
5149 * @author Mikhail Polivakha
50+ * @author Sergey Korotaev
5251 */
5352public class JdbcRepositoryFactoryBean <T extends Repository <S , ID >, S , ID extends Serializable >
5453 extends TransactionalRepositoryFactoryBeanSupport <T , S , ID > implements ApplicationEventPublisherAware {
@@ -58,7 +57,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
5857 private RelationalMappingContext mappingContext ;
5958 private JdbcConverter converter ;
6059 private DataAccessStrategy dataAccessStrategy ;
61- private QueryMappingConfiguration queryMappingConfiguration = QueryMappingConfiguration . EMPTY ;
60+ private QueryMappingConfiguration queryMappingConfiguration ;
6261 private NamedParameterJdbcOperations operations ;
6362 private EntityCallbacks entityCallbacks ;
6463 private Dialect dialect ;
@@ -124,7 +123,6 @@ public void setDataAccessStrategy(DataAccessStrategy dataAccessStrategy) {
124123 * @param queryMappingConfiguration can be {@literal null}. {@link #afterPropertiesSet()} defaults to
125124 * {@link QueryMappingConfiguration#EMPTY} if {@literal null}.
126125 */
127- @ Autowired (required = false )
128126 public void setQueryMappingConfiguration (QueryMappingConfiguration queryMappingConfiguration ) {
129127
130128 Assert .notNull (queryMappingConfiguration , "QueryMappingConfiguration must not be null" );
@@ -157,9 +155,14 @@ public void setBeanFactory(BeanFactory beanFactory) {
157155 @ Override
158156 public void afterPropertiesSet () {
159157
160- Assert .state (this .mappingContext != null , "MappingContext is required and must not be null" );
161158 Assert .state (this .converter != null , "RelationalConverter is required and must not be null" );
162159
160+ if (mappingContext == null ) {
161+ Assert .state (beanFactory != null , "If no MappingContext are set a BeanFactory must be available" );
162+
163+ this .mappingContext = beanFactory .getBean (RelationalMappingContext .class );
164+ }
165+
163166 if (this .operations == null ) {
164167
165168 Assert .state (beanFactory != null , "If no JdbcOperations are set a BeanFactory must be available" );
@@ -168,7 +171,10 @@ public void afterPropertiesSet() {
168171 }
169172
170173 if (this .queryMappingConfiguration == null ) {
171- this .queryMappingConfiguration = QueryMappingConfiguration .EMPTY ;
174+ Assert .state (beanFactory != null , "If no QueryMappingConfiguration are set a BeanFactory must be available" );
175+
176+ this .queryMappingConfiguration = beanFactory .getBeanProvider (QueryMappingConfiguration .class )
177+ .getIfAvailable (() -> QueryMappingConfiguration .EMPTY );
172178 }
173179
174180 if (this .dataAccessStrategy == null ) {
0 commit comments