-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow resolving Micronaut beans definitions in a modular application (#…
…10982) Uses the `jrt` URI protocol to resolve Micronaut bean definitions from modules if the protocol available. Since this protocol is not available on native image the PR catches the exception and ignores the provider being missing. This fixes #10842 --------- Co-authored-by: Graeme Rocher <graeme.rocher@oracle.com>
- Loading branch information
1 parent
608aedb
commit f3b381a
Showing
6 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/src/test/java/io/micronaut/core/io/service/SoftServiceLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.micronaut.core.io.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.module.Configuration; | ||
import java.lang.module.ModuleFinder; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.micronaut.core.io.service.SoftServiceLoader.ServiceCollector; | ||
|
||
public class SoftServiceLoaderTest { | ||
|
||
@Test | ||
void findServicesUsingJrtScheme() { | ||
String modulename = "io.micronaut.core.test"; | ||
ModuleFinder finder = ModuleFinder.of(Path.of("build/resources/test/test.jar")); | ||
ModuleLayer parent = ModuleLayer.boot(); | ||
Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of(modulename)); | ||
ClassLoader scl = ClassLoader.getSystemClassLoader(); | ||
ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl); | ||
|
||
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); | ||
try { | ||
Thread.currentThread().setContextClassLoader(layer.findLoader(modulename)); | ||
|
||
ServiceCollector<String> collector = SoftServiceLoader.newCollector("io.micronaut.inject.BeanDefinitionReference", null, layer.findLoader(modulename), Function.identity()); | ||
List<String> services = new ArrayList<>(); | ||
collector.collect(services::add); | ||
|
||
assertEquals(1, services.size()); | ||
assertEquals("io.micronaut.logging.$PropertiesLoggingLevelsConfigurer$Definition", services.get(0)); | ||
} | ||
finally { | ||
Thread.currentThread().setContextClassLoader(oldLoader); | ||
} | ||
} | ||
} |
Binary file not shown.