【问题标题】:Connect "MicroService Gateway" with "UAA Server" Jhipster 3.5.0将“微服务网关”与“UAA 服务器”Jhipster 3.5.0 连接起来
【发布时间】:2016-11-25 05:49:49
【问题描述】:

我创建了一个 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
  • 我在“docker-compose”中创建了 docker 容器,并且创建得很好。
  • 我必须在网关上添加一些额外的配置才能使用服务器 UAA?
  • 我在容器网关中得到以下错误跟踪:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.oauth2.provider.token.TokenStore org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration.tokenStore; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenStore' defined in class path resource [com/abalia/elser/config/MicroserviceSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.TokenStore]: Factory method 'tokenStore' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtAccessTokenConverter' defined in class path resource [com/abalia/elser/config/MicroserviceSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter]: Factory method 'jwtAccessTokenConverter' threw exception; nested exception is java.lang.IllegalStateException: No instances available for elseruaa...

非常感谢您的帮助。

【问题讨论】:

标签: jhipster microservices


【解决方案1】:

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

screencast

【讨论】:

    【解决方案2】:

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

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

     @Inject
    private DiscoveryClient discoveryClient;
    

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

    discoveryClient.getServices();
    

    【讨论】:

    • 在initApplication 方法中将@EnableDiscoveryClient 添加到您的Application(.java) 和@Inject DiscoveryClient 不是更好吗?还是我们每次想要获取更新列表的密钥时都需要调用它。
    【解决方案3】:

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

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

    【讨论】:

    • 我遇到了与 3.5.0 相同的问题
    • 您是否查看了注册表仪表板以查看 uaa 服务器是否已注册?
    • 我认为@GaëlMarziou 是对的。 UAA 需要在资源服务器(或“微服务”)之前运行并在 jhipster 注册表中注册,因为资源服务器会向正在运行的 UAA 询问他们验证 JWT 所需的公钥。由于该顺序,一个简单的“docker-compose up”将无法工作。您可能需要创建一个脚本来对启动进行排序,例如:github.com/kbastani/spring-cloud-event-sourcing-example/blob/…(请注意,此示例项目不是 jhipster 项目)。另外:github.com/jhipster/generator-jhipster/issues/…
    • 是的,这很正常,但即使当我尝试使用 uaa 连接网关时我也得到了 npe,而且我不使用 docker。一切都在 Jhipster 3.4.2 上运行
    • 从3.4.2开始,网关、UAA、UAA微服务都有变化,你都升级了吗?
    【解决方案4】:

    更改您的 MobileSecurityConfiguration

    @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();
    

    解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-18
      • 2018-12-10
      • 2023-03-27
      • 1970-01-01
      • 2018-10-04
      • 2017-09-11
      • 2019-04-06
      • 2018-12-31
      相关资源
      最近更新 更多