Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse-microprofiles config throws No ConfigProviderResolver implementation found

I am using eclipse-microprofiles-config v1.1 in my jersey 2.26.

My complete build.gradle is as follows.

apply plugin: 'java'
apply plugin: 'war'

repositories {
    mavenCentral()
}

war{
    archiveName = 'pqr.war'
}

dependencies {
    compile 'javax:javaee-api:7.0'
    compile 'javax.ws.rs:javax.ws.rs-api:2.0'
    compile 'org.glassfish.jersey.core:jersey-common:2.26'
    compile 'org.glassfish.jersey.core:jersey-client:2.26-b03'
    compile 'org.glassfish.jersey.core:jersey-server:2.26'
    compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.26'
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.26'
    compile 'org.glassfish.jersey.media:jersey-media-moxy:2.26'
    compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'
    compile 'org.eclipse.microprofile.config:microprofile-config-api:1.1'
}

I have the required properties file located at {PROJECT_ROOT}/src/main/webapp/META-INF/microprofile-config.properties in whichs content is

// Higher ordinal value so that this configuration source will take precedense
config_ordinal = 599999999 
foo.bar = abcdefghijklmnopqrstuvwxyz

Whenever I try to get this configuration as

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

@Path(value = "awesomeService")
public class AwesomeService {

    @GET
    @Path(value = "test")
    public String someOperation() {

        Config config = ConfigProvider.getConfig(); // fails here
        String value = config.getValue("foo.bar", String.class);

        return value;
    }

}

it throws "No ConfigProviderResolver implementation found" although ConfigProviderResolver.class is in the classpath. Im using glassfish 4 for my deployment. Where have I got it wrong. Following is the server log from glassfish.

[2017-12-09T20:34:17.296+0530] [glassfish 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=27 _ThreadName=http-listener-1(1)] [timeMillis: 1512831857296] [levelV$
lue: 900] [[
  StandardWrapperValve[org.pqr.rest.AppConfig]: Servlet.service() for servlet org.pqr.rest.AppConfig threw exception
java.lang.IllegalStateException: No ConfigProviderResolver implementation found!
        at org.eclipse.microprofile.config.spi.ConfigProviderResolver.instance(ConfigProviderResolver.java:122)
        at org.eclipse.microprofile.config.ConfigProvider.<clinit>(ConfigProvider.java:74)
        at org.pqr.rest.AwesomeService.someOperation(AwesomeService.java:16)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
        at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)

A sample project which causes this problem can be downloaded here. https://github.com/kalpacg/eclipse-microprofile-config

like image 510
Kalpa Gunarathna Avatar asked Feb 05 '26 16:02

Kalpa Gunarathna


1 Answers

The error is correct. MicroProfile Config is an API, a specification. it is not an implementation. To have an implementation you could use something like Geronimo Config as a standalone library.

Also note, you may need to place the properties file in your build under src/main/resources/META-INF, in case the property fails to load.

like image 54
John Ament Avatar answered Feb 07 '26 18:02

John Ament



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!