【问题标题】:SpringBoot: Eureka server is not discovering OAuth2 secure microserviceSpring Boot:Eureka 服务器未发现 OAuth2 安全微服务
【发布时间】:2018-11-03 01:11:19
【问题描述】:

我有一个带有配置的 Eureka 服务器

# Eureka configuration

    eureka.instance.hostname: localhost
    eureka.client.registerWithEureka: false
    eureka.client.fetchRegistry: false
    eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

此外,在启用 Eureka Discovery 的情况下运行客户和订单的两个微服务。我想在customers微服务中访问Orders微服务,但是eureka没有发现order微服务。

在我的两个服务中,安全性都是这样实现的

@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.cors().and().csrf().disable()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().authorizeRequests().antMatchers("/api/**").authenticated()
                .and().authorizeRequests().antMatchers("/swagger-ui.html").permitAll()
                .and().authorizeRequests().antMatchers("/**").authenticated();
    }
}

【问题讨论】:

  • 下面的答案有帮助吗?

标签: spring-boot microservices netflix-eureka


【解决方案1】:

您似乎缺少@EnableDiscoveryClient 客户端注释。它通常与@SpringBootApplication 一起使用。

@EnableDiscoveryClient 激活 Netflix Eureka DiscoveryClient 实现。还有其他实现 其他服务注册中心,例如 Hashicorp 的 Consul 或 Apache Zookeeper。

参考:https://spring.io/guides/gs/service-registration-and-discovery/

【讨论】:

  • 嗨朋友,有一些不同的参数需要设置以使其在云上可用。我已经通过某人的帮助解决了这个问题。
猜你喜欢
  • 2018-03-17
  • 2014-12-27
  • 2018-03-25
  • 2020-08-17
  • 1970-01-01
  • 2020-06-16
  • 2016-12-21
  • 2022-01-03
  • 2020-04-17
相关资源
最近更新 更多