连接 "MicroService Gateway" 与 "UAA Server" Jhipster 3.5.0

Connect "MicroService Gateway" with "UAA Server" Jhipster 3.5.0

我创建了一个 UAA 服务器:

? (1/16) Which *type* of application would you like to create? [BETA] JHipster UAA server (for microservice OAuth2 authentication)

然后我创建了一个微服务网关:

? (1/16) Which *type* of application would you like to create? Microservice gateway
...
? (6/16) What is the folder path of your UAA application?. ../elseruaa

非常感谢您的帮助。

Caused by: java.lang.IllegalStateException: No instances available for elseruaa 由 RibbonLoadBalancerClient 报告。

我不是最新的 uaa 支持,但您的网关似乎无法在已注册到您的 JHipster 注册表(Eureka 服务器)的 Eureka 客户端列表中找到名为 elseruaa 的服务).所以要么你忘记启动 elseruaa 要么它用另一个名字注册了。

我遇到了同样的问题。花费数小时后,终于通过在 MicroserviceSecurityConfiguration.java 中添加以下内容修复了错误:

注入org.springframework.cloud.client.discovery.DiscoveryClient

 @Inject
private DiscoveryClient discoveryClient;

在MicroserviceSecurityConfiguration.java的任一方法中(我选择getKeyFromAuthorizationServer方法),添加如下内容:

discoveryClient.getServices();

我创建了一个 youtube 截屏视频来展示如何使用 UAA 创建 jhipster (3.5.1) 微服务​​。我相信您面临的问题与服务的启动顺序有关,或者旧服务未使用 3.5.0+ 代码重新生成。正如您在截屏视频和 github 上的源代码中看到的那样,它按原样工作。

screencast

更改您的移动安全配置

@Inject
private DiscoveryClient discoveryClient;

private String getKeyFromAuthorizationServer() {
          List<String> services = discoveryClient.getServices();

          HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
          String value = (String) this.keyUriRestTemplate
              .exchange("http://uaa/oauth/token_key", HttpMethod.GET, request, Map.class).getBody()
              .get("value");

          return value;
      }

所以基本上只有一行:

List<String> services = discoveryClient.getServices();

解决这个问题。