New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service Loader does not work in Spring Boot #40
Comments
Hi @PRIESt512. Thanks for raising an issue & for the link! I've also come across https://stackoverflow.com/a/36228195, which made me wonder if the context classloader might get weird if threads are being pooled. This can cause classloader leaks across deployments. Also considering that the provider list is kept statically. I'm thinking if the classloader that loaded |
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 |
Any plans to fix this? I have the same problem while adding Methanol to a Spring Boot app. Included methanol-jackson as a dependency, but had to use auto-service to register the encoder and decoder for Jackson. Otherwise, I got an error stating that no supported Decoder was found. |
@laxika It seems that the solution is to pass Also, for reference, where you installing the jackson decoder as a module or from the classpath? Do you have any idea why auto-service would work? Considering it only writes the |
@mizosoft Well, to make this solution work, I would need to fork the project and build my custom jar for it right? I saw no way to override ServiceCache or ServiceLoader. To be honest I really want to avoid that. Tried the deploy my JAR to a test server then noticed that auto-service was not working there. However, it is working in the IDE (IntelliJ clicking on run). I think it works because in the IDE the classpath is different.
I have declared it as a dependency in Gradle. So from the classpath. Ended up creating my own decoder with
|
@laxika No need to override. I've locally tested passing Tricky part is testing in CI. Since the problem seems to only affect the runnable jar (that's why running from IntelliJ works), it has to be tested by invoking it from JUnit through the command line. Not sure if there's a standard way to do this though. Anyhow, I'll try to submit a PR shortly! |
I'm not 100% sure this was fixed; I'm on 1.6.0 and for me it works from intellij but when running from the jar I get
|
@chadselph The fix is pending for the repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
implementation 'com.github.mizosoft.methanol:methanol:1.7.0-SNAPSHOT'
} |
Sorry, I should have checked that! |
Hi, definition Decoder and Encoder are not defined in the system.
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
The text was updated successfully, but these errors were encountered: