16
16
package org .springframework .data .jdbc .repository .support ;
17
17
18
18
import java .io .Serializable ;
19
-
20
19
import org .springframework .beans .factory .BeanFactory ;
21
- import org .springframework .beans .factory .annotation .Autowired ;
22
20
import org .springframework .context .ApplicationEventPublisher ;
23
21
import org .springframework .context .ApplicationEventPublisherAware ;
24
22
import org .springframework .data .jdbc .core .convert .DataAccessStrategy ;
49
47
* @author Hebert Coelho
50
48
* @author Chirag Tailor
51
49
* @author Mikhail Polivakha
50
+ * @author Sergey Korotaev
52
51
*/
53
52
public class JdbcRepositoryFactoryBean <T extends Repository <S , ID >, S , ID extends Serializable >
54
53
extends TransactionalRepositoryFactoryBeanSupport <T , S , ID > implements ApplicationEventPublisherAware {
@@ -58,7 +57,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
58
57
private RelationalMappingContext mappingContext ;
59
58
private JdbcConverter converter ;
60
59
private DataAccessStrategy dataAccessStrategy ;
61
- private QueryMappingConfiguration queryMappingConfiguration = QueryMappingConfiguration . EMPTY ;
60
+ private QueryMappingConfiguration queryMappingConfiguration ;
62
61
private NamedParameterJdbcOperations operations ;
63
62
private EntityCallbacks entityCallbacks ;
64
63
private Dialect dialect ;
@@ -124,7 +123,6 @@ public void setDataAccessStrategy(DataAccessStrategy dataAccessStrategy) {
124
123
* @param queryMappingConfiguration can be {@literal null}. {@link #afterPropertiesSet()} defaults to
125
124
* {@link QueryMappingConfiguration#EMPTY} if {@literal null}.
126
125
*/
127
- @ Autowired (required = false )
128
126
public void setQueryMappingConfiguration (QueryMappingConfiguration queryMappingConfiguration ) {
129
127
130
128
Assert .notNull (queryMappingConfiguration , "QueryMappingConfiguration must not be null" );
@@ -157,9 +155,14 @@ public void setBeanFactory(BeanFactory beanFactory) {
157
155
@ Override
158
156
public void afterPropertiesSet () {
159
157
160
- Assert .state (this .mappingContext != null , "MappingContext is required and must not be null" );
161
158
Assert .state (this .converter != null , "RelationalConverter is required and must not be null" );
162
159
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
+
163
166
if (this .operations == null ) {
164
167
165
168
Assert .state (beanFactory != null , "If no JdbcOperations are set a BeanFactory must be available" );
@@ -168,7 +171,10 @@ public void afterPropertiesSet() {
168
171
}
169
172
170
173
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 );
172
178
}
173
179
174
180
if (this .dataAccessStrategy == null ) {
0 commit comments