GH-1062 - ApplicationModuleExporter now exposes ApplicationModuleInitializer beans.

This commit is contained in:
Oliver Drotbohm
2025-02-21 22:49:28 +01:00
parent 8fb7f07b4a
commit 19db2339bd
6 changed files with 58 additions and 1 deletions

View File

@@ -301,6 +301,23 @@ public class ApplicationModule implements Comparable<ApplicationModule> {
.toList();
}
/**
* Returns all {@link SpringBean}s assignable to the given type.
*
* @param type must not be {@literal null}.
* @return will never be {@literal null}.
* @since 1.4
*/
public List<SpringBean> getSpringBeans(Class<?> type) {
Assert.notNull(type, "Type must not be null!");
return getSpringBeansInternal().stream() //
.map(it -> SpringBean.of(it, this)) //
.filter(it -> it.isAssignableTo(type))
.toList();
}
/**
* Returns the {@link ArchitecturallyEvidentType} for the given type.
*

View File

@@ -106,6 +106,19 @@ public class SpringBean {
return ArchitecturallyEvidentType.of(type, module.getSpringBeansInternal());
}
/**
* Returns whether the bean is assignable to the given type.
*
* @param type must not be {@literal null}.
* @since 1.4
*/
public boolean isAssignableTo(Class<?> type) {
Assert.notNull(type, "Type must not be null!");
return this.type.isAssignableTo(type);
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)

View File

@@ -30,6 +30,7 @@ import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.modulith.ApplicationModuleInitializer;
import org.springframework.modulith.core.ApplicationModule;
import org.springframework.modulith.core.ApplicationModuleDependency;
import org.springframework.modulith.core.ApplicationModuleIdentifier;
@@ -37,6 +38,7 @@ import org.springframework.modulith.core.ApplicationModules;
import org.springframework.modulith.core.DependencyType;
import org.springframework.modulith.core.NamedInterface;
import org.springframework.modulith.core.NamedInterfaces;
import org.springframework.modulith.core.SpringBean;
import org.springframework.util.Assert;
import com.tngtech.archunit.core.domain.JavaClass;
@@ -137,6 +139,10 @@ public class ApplicationModulesExporter {
if (details.equals(Details.FULL)) {
json.put("namedInterfaces", toNamedInterfaces(module.getNamedInterfaces()));
json.put("initializers", module.getSpringBeans(ApplicationModuleInitializer.class).stream()
.map(SpringBean::getType)
.map(JavaClass::getName)
.toList());
}
json.put("dependencies", module.getDirectDependencies(modules).stream() //