GH-1015 - ModulithMetadata obtained from a package now considers @Modulithic annotations.
This commit is contained in:
@@ -40,6 +40,11 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -73,12 +78,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
|
||||
@@ -18,12 +18,17 @@ package org.springframework.modulith.core;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.modulith.Modulith;
|
||||
import org.springframework.modulith.Modulithic;
|
||||
import org.springframework.modulith.core.Types.SpringTypes;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Core metadata about the modulithic application.
|
||||
@@ -56,13 +61,26 @@ public interface ModulithMetadata {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ModulithMetadata} instance for the given package.
|
||||
* Creates a new {@link ModulithMetadata} instance for the given package. Inspects the package for classes annotated
|
||||
* with {@link Modulithic} to pick up additional configuration.
|
||||
*
|
||||
* @param javaPackage must not be {@literal null} or empty.
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
public static ModulithMetadata of(String javaPackage) {
|
||||
return SpringBootModulithMetadata.of(javaPackage);
|
||||
|
||||
var provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Modulithic.class));
|
||||
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(javaPackage);
|
||||
|
||||
if (candidates.size() != 1) {
|
||||
return SpringBootModulithMetadata.of(javaPackage);
|
||||
}
|
||||
|
||||
var className = candidates.iterator().next().getBeanClassName();
|
||||
|
||||
return of(ClassUtils.resolveClassName(className, ModulithMetadata.class.getClassLoader()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,5 +20,5 @@ import org.springframework.modulith.Modulithic;
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Modulithic
|
||||
@Modulithic(systemName = "customSystemName")
|
||||
public class EmptyApplication {}
|
||||
|
||||
@@ -74,6 +74,14 @@ class ModulithMetadataUnitTest {
|
||||
assertThat(metadata.getBasePackages()).containsExactly(getClass().getPackageName());
|
||||
}
|
||||
|
||||
@Test // GH-1015
|
||||
void considersModulithicOnPackageLookup() {
|
||||
|
||||
var metadata = ModulithMetadata.of("empty");
|
||||
|
||||
assertThat(metadata.getSystemName()).hasValue("customSystemName");
|
||||
}
|
||||
|
||||
@Modulith(additionalPackages = "com.acme.foo", //
|
||||
sharedModules = "shared.module", //
|
||||
systemName = "systemName", //
|
||||
|
||||
Reference in New Issue
Block a user