|
18 | 18 | import java.util.List;
|
19 | 19 | import java.util.Optional;
|
20 | 20 | import java.util.function.Supplier;
|
| 21 | +import java.util.Set; |
21 | 22 | import java.util.stream.Stream;
|
22 | 23 |
|
| 24 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 25 | +import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; |
| 26 | +import org.springframework.core.type.filter.AnnotationTypeFilter; |
23 | 27 | import org.springframework.modulith.Modulith;
|
24 | 28 | import org.springframework.modulith.Modulithic;
|
25 | 29 | import org.springframework.modulith.core.Types.SpringTypes;
|
26 | 30 | import org.springframework.util.Assert;
|
| 31 | +import org.springframework.util.ClassUtils; |
27 | 32 |
|
28 | 33 | /**
|
29 | 34 | * Core metadata about the modulithic application.
|
@@ -56,13 +61,26 @@ public static ModulithMetadata of(Class<?> annotated) {
|
56 | 61 | }
|
57 | 62 |
|
58 | 63 | /**
|
59 |
| - * Creates a new {@link ModulithMetadata} instance for the given package. |
| 64 | + * Creates a new {@link ModulithMetadata} instance for the given package. Inspects the package for classes annotated |
| 65 | + * with {@link Modulithic} to pick up additional configuration. |
60 | 66 | *
|
61 | 67 | * @param javaPackage must not be {@literal null} or empty.
|
62 | 68 | * @return will never be {@literal null}.
|
63 | 69 | */
|
64 | 70 | public static ModulithMetadata of(String javaPackage) {
|
65 |
| - return SpringBootModulithMetadata.of(javaPackage); |
| 71 | + |
| 72 | + var provider = new ClassPathScanningCandidateComponentProvider(false); |
| 73 | + provider.addIncludeFilter(new AnnotationTypeFilter(Modulithic.class)); |
| 74 | + |
| 75 | + Set<BeanDefinition> candidates = provider.findCandidateComponents(javaPackage); |
| 76 | + |
| 77 | + if (candidates.size() != 1) { |
| 78 | + return SpringBootModulithMetadata.of(javaPackage); |
| 79 | + } |
| 80 | + |
| 81 | + var className = candidates.iterator().next().getBeanClassName(); |
| 82 | + |
| 83 | + return of(ClassUtils.resolveClassName(className, ModulithMetadata.class.getClassLoader())); |
66 | 84 | }
|
67 | 85 |
|
68 | 86 | /**
|
|
0 commit comments