File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
main/java/org/springframework/data/repository/support
test/java/org/springframework/data/repository/support Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,9 @@ public boolean hasRepositoryFor(Class<?> domainClass) {
122
122
123
123
Assert .notNull (domainClass , DOMAIN_TYPE_MUST_NOT_BE_NULL );
124
124
125
- return repositoryFactoryInfos .containsKey (domainClass );
125
+ Class <?> userClass = ClassUtils .getUserClass (domainClass );
126
+
127
+ return repositoryFactoryInfos .containsKey (userClass );
126
128
}
127
129
128
130
/**
@@ -135,7 +137,9 @@ public Optional<Object> getRepositoryFor(Class<?> domainClass) {
135
137
136
138
Assert .notNull (domainClass , DOMAIN_TYPE_MUST_NOT_BE_NULL );
137
139
138
- Optional <String > repositoryBeanName = Optional .ofNullable (repositoryBeanNames .get (domainClass ));
140
+ Class <?> userClass = ClassUtils .getUserClass (domainClass );
141
+ Optional <String > repositoryBeanName = Optional .ofNullable (repositoryBeanNames .get (userClass ));
142
+
139
143
return beanFactory .flatMap (it -> repositoryBeanName .map (it ::getBean ));
140
144
}
141
145
Original file line number Diff line number Diff line change 29
29
import org .junit .Test ;
30
30
import org .junit .runner .RunWith ;
31
31
import org .mockito .junit .MockitoJUnitRunner ;
32
+ import org .springframework .aop .framework .ProxyFactory ;
32
33
import org .springframework .beans .factory .support .AbstractBeanDefinition ;
33
34
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
34
35
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
@@ -140,6 +141,23 @@ public void exposesRepositoryFactoryInformationForRepository() {
140
141
.hasValueSatisfying (it -> assertThat (it .getRepositoryInterface ()).isEqualTo (PersonRepository .class ));
141
142
}
142
143
144
+ @ Test // DATACMNS-1215
145
+ public void exposesRepositoryForProxyType () {
146
+
147
+ ProxyFactory factory = new ProxyFactory ();
148
+ factory .setTarget (new Person ());
149
+ factory .setProxyTargetClass (true );
150
+
151
+ Object proxy = factory .getProxy ();
152
+
153
+ assertThat (ClassUtils .isCglibProxy (proxy )).isTrue ();
154
+
155
+ Repositories repositories = new Repositories (context );
156
+
157
+ assertThat (repositories .hasRepositoryFor (proxy .getClass ())).isTrue ();
158
+ assertThat (repositories .getRepositoryFor (proxy .getClass ())).isNotEmpty ();
159
+ }
160
+
143
161
class Person {}
144
162
145
163
class Address {}
You can’t perform that action at this time.
0 commit comments