File tree 4 files changed +83
-2
lines changed
main/java/org/springframework/data/repository/config
test/java/org/springframework/data/repository/config
4 files changed +83
-2
lines changed Original file line number Diff line number Diff line change 16
16
package org .springframework .data .repository .config ;
17
17
18
18
import java .io .IOException ;
19
- import java .util .Arrays ;
19
+ import java .util .LinkedHashSet ;
20
+ import java .util .Set ;
20
21
import java .util .stream .Stream ;
21
22
22
23
import org .springframework .beans .factory .BeanDefinitionStoreException ;
32
33
* @author Mark Paluch
33
34
* @author Oliver Gierke
34
35
* @author Johannes Englmeier
36
+ * @author Yanming Zhou
35
37
* @since 2.1
36
38
*/
37
39
public class FragmentMetadata {
@@ -52,10 +54,25 @@ public Stream<String> getFragmentInterfaces(String interfaceName) {
52
54
53
55
Assert .hasText (interfaceName , "Interface name must not be null or empty" );
54
56
55
- return Arrays . stream ( getClassMetadata ( interfaceName ).getInterfaceNames () ) //
57
+ return getAllSuperInterfaces ( interfaceName ).stream ( ) //
56
58
.filter (this ::isCandidate );
57
59
}
58
60
61
+ /**
62
+ * Returns all super interfaces of the given interface.
63
+ *
64
+ * @param interfaceName must not be {@literal null} or empty.
65
+ * @return
66
+ */
67
+ private Set <String > getAllSuperInterfaces (String interfaceName ) {
68
+ Set <String > interfaces = new LinkedHashSet <>();
69
+ for (String ifc : getClassMetadata (interfaceName ).getInterfaceNames ()) {
70
+ interfaces .add (ifc );
71
+ interfaces .addAll (getAllSuperInterfaces (ifc ));
72
+ }
73
+ return interfaces ;
74
+ }
75
+
59
76
/**
60
77
* Returns whether the given interface is a fragment candidate.
61
78
*
Original file line number Diff line number Diff line change 46
46
*
47
47
* @author Oliver Gierke
48
48
* @author Mark Paluch
49
+ * @author Yanming Zhou
49
50
*/
50
51
@ ExtendWith (MockitoExtension .class )
51
52
class RepositoryBeanDefinitionRegistrarSupportUnitTests {
@@ -124,6 +125,18 @@ void shouldLimitImplementationBasePackages() {
124
125
assertBeanDefinitionRegisteredFor ("spiContribution" );
125
126
}
126
127
128
+
129
+ @ Test // GH-3212
130
+ void shouldRegisterIndirectSpiFragment () {
131
+
132
+ AnnotationMetadata metadata = new StandardAnnotationMetadata (ExcludedWithSpiFragement .class , true );
133
+
134
+ registrar .registerBeanDefinitions (metadata , registry );
135
+
136
+ assertBeanDefinitionRegisteredFor ("personRepository" );
137
+ assertBeanDefinitionRegisteredFor ("spiFragmentImplFragment" );
138
+ }
139
+
127
140
@ Test // DATACMNS-360
128
141
void registeredProfileRepositoriesIfProfileActivated () {
129
142
@@ -203,6 +216,9 @@ static class FragmentExclusionConfiguration {}
203
216
@ EnableRepositories (basePackageClasses = FragmentImpl .class )
204
217
static class LimitsImplementationBasePackages {}
205
218
219
+ @ EnableRepositories (basePackageClasses = org .springframework .data .repository .config .indirectspifragment .PersonRepository .class )
220
+ static class ExcludedWithSpiFragement {}
221
+
206
222
@ EnableRepositories (basePackageClasses = MyNestedRepository .class , considerNestedRepositories = true ,
207
223
excludeFilters = {
208
224
@ Filter (type = FilterType .ASSIGNABLE_TYPE ,
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2017-2024 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .springframework .data .repository .config .indirectspifragment ;
17
+
18
+ import org .springframework .data .mapping .Person ;
19
+ import org .springframework .data .repository .NoRepositoryBean ;
20
+ import org .springframework .data .repository .Repository ;
21
+ import org .springframework .data .repository .config .spifragment .SpiFragment ;
22
+
23
+ /**
24
+ * @author Yanming Zhou
25
+ */
26
+ @ NoRepositoryBean
27
+ public interface ExcludedRepository extends Repository <Person , String >, SpiFragment {}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2017-2024 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .springframework .data .repository .config .indirectspifragment ;
17
+
18
+ /**
19
+ * @author Yanming Zhou
20
+ */
21
+ public interface PersonRepository extends ExcludedRepository {}
You can’t perform that action at this time.
0 commit comments