-
Notifications
You must be signed in to change notification settings - Fork 18
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
Json validation provider not found #40
Comments
@anitadc |
Yes. I am using spring-boot-maven-plugin 2.1.2 |
@anitadc |
Difference is - I am calling this justify parser asynchronously using completablefuture and external executor |
Can you provide me with a sample project that reproduces the reported problem? |
To generate issue, initialize JsonValidationService within child thread instead of static or Singleton object. Do below changes In your sample project - CompletableFuture.runAsync(()-> { |
Thank you @anitadc @SpringBootApplication
public class Application implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(Application.class);
@Override
public void run(String... args) throws Exception {
var future = CompletableFuture.runAsync(() -> {
JsonProvider provider = loadProvider();
LOG.info(provider.getClass().getName());
}).exceptionally(e -> {
LOG.error(e.getMessage());
return null;
});
future.get();
}
private JsonProvider loadProvider() {
ServiceLoader<JsonProvider> loader = ServiceLoader.load(JsonProvider.class);
Iterator<JsonProvider> it = loader.iterator();
if (it.hasNext()) {
return it.next();
} else {
throw new IllegalStateException("No service provider found");
}
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
} pom.xml (with Justify removed) <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<classifier>module</classifier>
<version>${jakarta.json.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies> Therefore this is NOT a problem of Justify. I suspect that the problem is due to a restriction or bug of spring-boot-maven-plugin using with |
I added a fallback logic to JsonValidationService#newInstance(). |
Correct. This will happen with any code like justify which will use ServiceLoader and current thread classloader. |
I appreciate this change. Hopefully this will work. I will confirm you. |
Did you add this fallback logic in 2.1.0 version?? Kindly publish this in maven repository. |
@anitadc |
I am facing same problem when running Spring boot application jar from command prompt. But It is working fine from eclipse and same application jar in other machine. I am using java11 and no module structure.
Originally posted by @anitadc in #18 (comment)
The text was updated successfully, but these errors were encountered: