question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Loader does not work in Spring Boot

See original GitHub issue

Hi, definition Decoder and Encoder are not defined in the system.

private List<S> loadProviders() {
    List<S> providers = new ArrayList<>();
    ServiceLoader.load(service, Thread.currentThread().getContextClassLoader()).stream()
        .forEach(p -> addProviderLenient(p, providers));
    return Collections.unmodifiableList(providers);
  }

change to “Thread.currentThread().getContextClassLoader()” solves the problem

P.S. - https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html#executable-jar.restrictions:

System classLoader: Launched applications should use Thread.getContextClassLoader() when loading classes (most libraries and frameworks do so by default). Trying to load nested jar classes with ClassLoader.getSystemClassLoader() fails. java.util.Logging always uses the system classloader. For this reason, you should consider a different logging implementation.

locally tested, the problem disappeared

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mizosoftcommented, May 5, 2022

@chadselph The fix is pending for the 1.7.0 release, which I’ll be able to finally cut this weekend. 1.6.0 is still affected. In the meantime, you can pull in 1.7.0-SNAPSHOT as follows:

repositories {
  maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
  }
}

dependencies {
  implementation 'com.github.mizosoft.methanol:methanol:1.7.0-SNAPSHOT'
}
2reactions
PRIESt512commented, Jun 10, 2021

I was also not sure about the ideality of this idea. For this reason, I didn’t make a pull request right away. I have a few days off from work in the near future. I will try to study this issue and conduct experiments. If anything happens, I will share the results and make a pull request

Read more comments on GitHub >

github_iconTop Results From Across the Web

ServiceLoader do not work in packaged Spring Boot apps
I noticed that Java's ServiceLoader mechanism doesn't work in packaged Spring Boot apps. Background. I've tried to use javax.script.
Read more >
ServiceLoader do not work in packaged Spring Boot apps
I noticed that Java's ServiceLoader mechanism doesn't work in packaged Spring Boot apps. Background. I've tried to use javax.script.
Read more >
ServiceLoader: The Built in DI Framework You've Probably ...
ServiceLoader provides the capability to find and instantiate registered instances of interfaces or abstract classes. For those farmiliar with ...
Read more >
Java Service Loader vs. Spring Factories Loader - DZone
In parallel to the Java Service Loader, Spring offers another Inversion of Control implementation. There's only a single property file involved, ...
Read more >
Java Service Provider Interface | Baeldung
At the heart of the SPI is the ServiceLoader class. This has the role of discovering and loading implementations lazily.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found