-
Notifications
You must be signed in to change notification settings - Fork 682
Introduce ManagedTypes. #2635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ManagedTypes. #2635
Conversation
* @since 3.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface ManagedTypes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about implementing Streamable<Class<?>>
here?
Supplier<Set<String>> basePackages) { | ||
|
||
String beanName = String.format("%s.managed-types", extension.getModulePrefix()); | ||
if (!registry.isBeanNameInUse(beanName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using multiple times @Enable…Repositories
can cause conflicts. Spring has somewhere a utility to generate unique bean names from a bean base name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved by not not scanning for types here. (see comment below).
src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java
Show resolved
Hide resolved
@@ -45,6 +49,10 @@ public class AnnotatedTypeScanner implements ResourceLoaderAware, EnvironmentAwa | |||
private @Nullable ResourceLoader resourceLoader; | |||
private @Nullable Environment environment; | |||
|
|||
private Consumer<ClassNotFoundException> classNotFoundAction = ex -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the idea behind the ClassNotFoundException
handling? Is this a response to a certain use case? If so, then we should make this concept more explicit with an ErrorHandler
.
* @return | ||
* @since 3.0 | ||
*/ | ||
default Collection<Class<? extends Annotation>> getIdentifyingAnnotations() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels a bit weird handing out identifying annotations to the outside of the config extension as the managed type scanning vs. repository scanning are located at two different abstractions.
Repository type scanning happens inside the RepositoryConfigurationExtension
. We still need to merge repository-managed types with the ones that we discover through the classpath scan.
How about returning a RepositoryConfigurations
object from getRepositoryConfigurations
that wraps Collection<RepositoryConfiguration<T>>
and provides a ManagedTypes
object?
Doing so would allow keeping all scanning-related operations within the extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not be doing the ManagedType
scanning in the RepositoryConfigurationDelegate
and just consider the domain types exposed by the repository declaration.
ManagedTypes
may be contributed by an external configuration source, such as Boot.
* @return new instance of {@link TypeScanner}. | ||
* @see #scanPackages(Collection) | ||
*/ | ||
default TypeScanner scanPackages(String... packageNames) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scanPackages
should be renamed to a name that is less imperative and expresses rather that this is a config option packagesToScan
or something like that, so that the imperative names (forEach
, collectAsSet
) remain as terminal methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking this 1 step further, perhaps all the typeScanner(..
) factory methods could be renamed to from(..)
and the scanPackages(..)
method could be renamed to inPackages(..)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
considered - TypeScanner
is likely to be dropped from this PR and move to another one.
* @return new instance of {@link TypeScanner}. | ||
* @see #scanPackages(String...) | ||
*/ | ||
TypeScanner scanPackages(Collection<String> packageNames); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note comment above.
29231f9
to
be84bca
Compare
That's merged and polished now. |
See: #2634