@@ -127,10 +127,16 @@ public RepositoryFactorySupport() {
127
127
* retrieval via the {@code RepositoryMethodContext} class. This is useful if an advised object needs to obtain
128
128
* repository information.
129
129
* <p>
130
- * Default is {@literal "false"}, in order to avoid unnecessary extra interception. This means that no guarantees are provided
131
- * that {@code RepositoryMethodContext} access will work consistently within any method of the advised object.
132
- *
133
- * @since 3.4.0
130
+ * Default is {@literal "false"}, in order to avoid unnecessary extra interception. This means that no guarantees are
131
+ * provided that {@code RepositoryMethodContext} access will work consistently within any method of the advised
132
+ * object.
133
+ * <p>
134
+ * Repository method metadata is also exposed if implementations within the {@link RepositoryFragments repository
135
+ * composition} implement {@link RepositoryMetadataAccess}.
136
+ *
137
+ * @since 3.4
138
+ * @see RepositoryMethodContext
139
+ * @see RepositoryMetadataAccess
134
140
*/
135
141
public void setExposeMetadata (boolean exposeMetadata ) {
136
142
this .exposeMetadata = exposeMetadata ;
@@ -345,7 +351,7 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
345
351
result .addAdvice (new MethodInvocationValidator ());
346
352
}
347
353
348
- if (this .exposeMetadata ) {
354
+ if (this .exposeMetadata || shouldExposeMetadata ( fragments ) ) {
349
355
result .addAdvice (new ExposeMetadataInterceptor (metadata ));
350
356
result .addAdvisor (ExposeInvocationInterceptor .ADVISOR );
351
357
}
@@ -616,6 +622,16 @@ private Lazy<ProjectionFactory> createProjectionFactory() {
616
622
return Lazy .of (() -> getProjectionFactory (this .classLoader , this .beanFactory ));
617
623
}
618
624
625
+ private static boolean shouldExposeMetadata (RepositoryFragments fragments ) {
626
+
627
+ for (RepositoryFragment <?> fragment : fragments ) {
628
+ if (fragment .getImplementation ().filter (RepositoryMetadataAccess .class ::isInstance ).isPresent ()) {
629
+ return true ;
630
+ }
631
+ }
632
+ return false ;
633
+ }
634
+
619
635
/**
620
636
* Method interceptor that calls methods on the {@link RepositoryComposition}.
621
637
*
0 commit comments