2017-12-09 23 views
1

私のジャージ2.26にeclipse-microprofiles-config v1.1を使用しています。eclipse-microprofiles config throws ConfigProviderResolverの実装が見つかりません

完全なbuild.gradleは次のとおりです。私はwhichsコンテンツに{PROJECT_ROOT}/src/main/webapp/META-INF/microprofile-config.properties で必要なプロパティファイルの場所に位置している

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' 
} 

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

私は

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; 
    } 

} 

としてこの設定を取得しようとするたびに、それは「見つかりませConfigProviderResolverの実装をスローしないでConfigProviderResolver.classはクラスパスにあります。私の展開にはglassfish 4を使っています。どこが間違っているのですか?以下は、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) 

この問題を引き起こすサンプルプロジェクトは、ここでダウンロードできます。 https://github.com/kalpacg/eclipse-microprofile-config

答えて

2

エラーは正しいです。 MicroProfile ConfigはAPI、仕様です。実装ではありません。実装するには、Geronimo Configのようなものをスタンドアロンのライブラリとして使用できます。

また、プロパティがロードされない場合は、src/main/resources/META-INFのビルドにプロパティファイルを配置する必要があります。

+0

本当に正しいです。私は、atleasetコアconfig APIには、microprofile-config.propertiesファイルなどのデフォルトの設定オプション用のConfigProvidersが含まれているという前提の下にありました。あなたの洞察に感謝します。 –

関連する問題