3

私はSpring CloudとSpringの外部設定という概念を新しく導入しました。実際は昨日開始されました。Springクラウドの設定クライアントのプロパティが解決されない

ローカルのGitリポジトリから1つの設定サーバを作成しました。これは、設定クライアントでもある1つのマイクロサービスと1つのユーレカ駆動サービス検出サーバです。以下は

私は主にインターネット上でさまざまなリソースから借りてきたコードである -

構成サーバー - application.yml:

server: 
    port: 8888 

spring: 
    cloud: 
    config: 
     server: 
     git: 
      uri: file:///${user.home}/config-repo 

コンフィグサーバ - メインクラス(ブートストラップ)

@EnableConfigServer 
@SpringBootApplication 
public class CloudConfigServerApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(CloudConfigServerApplication.class, args); 
    } 
} 

config-repoは私のマシン上のローカルgit repoで、configクライアントアプリケーションの名前を持つ.ymlファイルを持っています。つまり、authmanager.yml

eureka: 
    client: 
     serviceUrl: 
      defaultZone: http://127.0.0.1:8761/eureka/ 
     healthcheck: 
      enabled: true 
     lease: 
      duration: 5 
spring: 
    application: 
     data: 
      mongodb: 
       host: localhost 
       port: 27017 
       database: edc_mc 
logging: 
    level: 
     org.exampledriven.eureka.customer.shared.CustomerServiceFeignClient: FULL 

は今のconfigサーバを実行した後、以下のエンドポイントの出力であるhttp://localhost:8888/authmanager/default -

{"name":"authmanager","profiles":["default"],"label":"master","version":"0ca6ca7b4502b9bb6ce1bf8efeb25516682cf79a","propertySources":[{"name":"file:///C:\\Users\\username/config-repo/authmanager.yml","source":{"eureka.client.serviceUrl.defaultZone":"http://127.0.0.1:8761/eureka/","eureka.client.healthcheck.enabled":true,"eureka.client.lease.duration":5,"spring.application.data.mongodb.host":"localhost","spring.application.data.mongodb.port":27017,"spring.application.data.mongodb.database":"db_name","logging.level.org.exampledriven.eureka.customer.shared.CustomerServiceFeignClient":"FULL"}}]} 

マイクロサービス+コンフィグクライアントコード -

bootstrap.yml -

server: 
    port: 9097 

spring: 
    application: 
    name: authmanager 
    cloud: 
    config: 
     uri: http://localhost:8888 

クライアント - メインクラス(ブートストラップ) -

明確さのためにコードの残りの部分をスキップ

@RefreshScope 
@RestController 
@RequestMapping("/auth") 
public class MyController { 

    @Value("${spring.application.data.mongodb.database}") 
    String env_var; 

- 私は、設定ファイルのプロパティを使用したい設定クライアント、中

@SpringBootApplication 
@EnableDiscoveryClient 
@EnableWebMvc 
public class CloudLoginManagerApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(CloudLoginManagerApplication.class, args); 
    } 
} 

コントローラクラス。 server.portは問題を与えていないような

Could not resolve placeholder 'spring.application.data.mongodb.database' in string value "${spring.application.data.mongodb.database}" 

その他のプロパティ -

これは私が取得していますエラーです。

私も環境インターフェイスの方法を試しましたが、それもnullを返します。

すべてのポインタをお願いします。私は今、行き詰まっています。あなたの依存関係にspring-cloud-starter-configを追加する必要がクラウドの設定を有効にするには

おかげで、

AJ

+0

私のために働いています。あなたのコードに誤字があるかどうか確認してください。 – Patrick

+0

申し訳ありませんが、遅く返信して、これは私のために働いた。私が使用していた設定パラメータがどのように間違っていたのか。それに基づいて私は私のcofnigがworngだと思った。とにかく反応するためには多くのことがあります。 – aj1984

+0

@ aj1984彼は問題を解決した正確なことを教えてください。私も同じ問題に直面しています –

答えて

5

。/env(アクチュエータを追加する必要がある可能性があります)をチェックして、利用可能なプロパティを確認して確認できます。

<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring-cloud-starter-config</artifactId> 
</dependency> 
+0

こんにちはジェフ、遅く返事を申し訳ありません、これは私のために働いた。私が使用していた設定パラメータがどのように間違っていたのか。それに基づいて私は私のcofnigがworngだと思った。とにかく反応するためには多くのことがあります。 – aj1984

+0

Hey Jeff、もう一度同じ問題にぶつかり、最後にあなたが実際に助けてくれた依存関係を突きつけました。ありがとう。 – aj1984

関連する問題