标签: spring-cloud

Spring-Cloud配置服务器忽略配置属性文件

我正在尝试创建一个Spring Cloud配置服务器,它从属性文件而不是github读取配置数据.服务器启动,但不提供文件中的属性.我在classpapath上有两个配置文件:

bootstrap.yml

spring:
application:
    name: config-server
Run Code Online (Sandbox Code Playgroud)

config-server.properties

foo=bar
Run Code Online (Sandbox Code Playgroud)

当我去url,据说应该给我foo属性的值:

curl  http://localhost:8888/admin/env/foo
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:"timestamp":1415298615005,"status":404,"error":"Not Found","exception":"org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint $ NoSuchPropertyException","message ":"没有这样的属性:foo","path":"/ admin/env/foo"}

我想知道我做错了什么?据我所知,属性文件名应与服务器名称匹配,以便服务器识别.


添加原生配置文件作为spencergibb建议没有帮助.我的application.properties看起来像:

server.port=8888
spring.profiles.active=native
spring.config.name=configserver
spring.application.name=configserver
Run Code Online (Sandbox Code Playgroud)

注意,我必须指定服务器端口.根据Spring Cloud Config Server文档,配置服务器默认在端口8888上启动.在我的情况下,除非我在配置中指定端口,否则服务器从8080开始.

POM文件没有父级和单个依赖项:

    <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
        <version>1.0.0.M2</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

该应用程序没有什么特别之处:

@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableConfigServer
public class ConfigurationApp {
    public static void main(String[] args) {
        SpringApplication.run(ConfigurationApp.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

configserver.properties文件包含一个条目:foo = bar

首先,我总是遇到启动错误

2014-11-07 09:35:42.852 ERROR 6972 --- [           main] b.c.PropertySourceBootstrapConfiguration : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/configserver/default/master":Connection refused: …
Run Code Online (Sandbox Code Playgroud)

java spring-cloud

6
推荐指数
1
解决办法
9687
查看次数

我可以拥有多个Spring Cloud Config Server吗?

我知道我可以使用多个存储库来跨多个存储库(可能是每个应用程序)分配我的配置,但是,我可以为这些存储库运行多个配置服务器,这样我们就可以避免单点故障了配置服务器'.

如果我们可以运行多个配置服务器,我如何抽象我的客户端访问任何一个特定的配置服务器?

更新(进一步阅读后):如果我使用负载均衡多个IP的URL,而不是在URI中使用IP,它是否会解决我在Config Server上单点故障的问题?

spring.cloud.config.uri: http ://myconfigserver.com

spring config spring-boot spring-cloud spring-cloud-config

6
推荐指数
1
解决办法
2977
查看次数

多个资源服务器oauth2客户端?Spring OAuth2 SSO

美好的一天,

我已经设置了一个实现SSO和API网关模式的工作示例(类似于此处描述的https://spring.io/guides/tutorials/spring-security-and-angular-js/#_the_api_gateway_pattern_angular_js_and_spring_security_part_iv).

该系统由单独的服务器组件组成:AUTH-SERVER,API-GATEWAY,SERVICE-DISCOVERY,RESOURCE/UI SERVER.

在API-GATEWAY(使用Spring Boot @EnableZuulProxy @ EnableOAuth2Sso实现)我已经配置了多个OAuth提供程序,包括使用JWT的我自己的OAuth服务器:

security:
  oauth2:
    client:
      accessTokenUri: http://localhost:9999/uaa/oauth/token
      userAuthorizationUri: http://localhost:9999/uaa/oauth/authorize
      clientId: acme
      clientSecret: acmesecret
      redirectUri: http://localhost:9000/login
  resource:
    jwt:
      key-value: |
      -----BEGIN PUBLIC KEY-----
      ...public-key...
      -----END PUBLIC KEY-----

facebook:
  client:
    clientId: 233668646673605
    clientSecret: 33b17e044ee6a4fa383f46ec6e28ea1d
    accessTokenUri: https://graph.facebook.com/oauth/access_token
    userAuthorizationUri: https://www.facebook.com/dialog/oauth
    tokenName: oauth_token
    authenticationScheme: query
    clientAuthenticationScheme: form
    redirectUri: http://localhost:8080
  resource:
    userInfoUri: https://graph.facebook.com/me

github:
  client:
    clientId: bd1c0a783ccdd1c9b9e4
    clientSecret: 1a9030fbca47a5b2c28e92f19050bb77824b5ad1
    accessTokenUri: https://github.com/login/oauth/access_token
    userAuthorizationUri: https://github.com/login/oauth/authorize
    clientAuthenticationScheme: form
  resource:
    userInfoUri: https://api.github.com/user

google:
  client:
    clientId: 1091750269931-152sv64o8a0vd5hg8v2lp92qd2d4i00r.apps.googleusercontent.com
    clientSecret: n4I4MRNLKMdv603SU95Ic9lJ
    accessTokenUri: https://www.googleapis.com/oauth2/v3/token
    userAuthorizationUri: …
Run Code Online (Sandbox Code Playgroud)

oauth spring-boot spring-security-oauth2 spring-cloud spring-oauth2

6
推荐指数
0
解决办法
3615
查看次数

RxJava测试:如何等待所有后台任务完成

TLDR:我在RxJava Observables中进行后台处理,我正在进行集成测试,我希望能够独立等待该处理完成,以确保从一次测试开始的后台处理不会干扰另一个测试.


简化,我有一个@RequestMapping方法,可以执行以下操作:

  • 在数据库中插入数据
  • 启动对该数据的异步处理(通过Feign,db更新进行http调用)
  • 什么都不返回(HttpStatus.NO_CONTENT)

这种异步处理以前是用a完成的ThreadPoolTaskExecutor.我们将转换到RxJava并希望删除此ThreadPoolTask​​Executor并使用RxJava进行后台处理.

所以我试图这样做的时候非常天真:

Observable
    .defer(() -> Observable.just(call to long blocking method) 
    .subscribeOn(Schedulers.io())
    .subscribe();
Run Code Online (Sandbox Code Playgroud)

最终目标当然是,一步一步,进入"调用长阻塞方法"并一直使用Observable.

在此之前,我想首先使我的集成​​测试工作.我通过对映射执行RestTemplate调试来测试它.由于大多数工作是异步的,我的调用返回非常快.现在我想找到一种方法来等待异步处理完成(以确保它不与另一个测试冲突).

在RxJava之前,我只计算ThreadPoolTask​​Executor中的任务并等到它达到0.

我怎么能用RxJava做到这一点?


我尝试了什么:

  • 我尝试使用RxJavaSchedulersHook立即使我的所有调度程序立即生效:这导致某处某种阻塞,代码执行在我的Feign调用之前停止(Feign在引擎盖下使用RxJava)
  • 我尝试使用Rx RxJavaObservableExecutionHook计算任务:我尝试保留订阅,并在isSubcribed = false时删除它们,但这根本不起作用(许多订阅者,计数永远不会下降)
  • 我试图将一个observeOn(immediate())放在真正的生产代码中.这似乎有效,我可以为运行时/测试阶段注入正确的调度程序,但我并不真正热衷于在我的实际生产代码中将代码用于测试目的.

我可能非常错误,或者过于复杂的事情,所以不要犹豫,纠正我的理由!

java rx-java spring-boot spring-cloud

6
推荐指数
2
解决办法
2451
查看次数

Spring Cloud - Registry Service端口定制

我想用Spring Cloud定制Eureka端口.使用下面的默认端口,服务注册表看起来正确(在提供的GUI中)

spring:
  application:
    name: services-registry
server:
  port: 8761

eureka:
  instance:
    hostname: localhost
    nonSecurePort: ${server.port}
  client:
    register-with-eureka: true
    fetch-registry: false
    service-url:
      default-zone: http://${eureka.instance.hostname}:${server.port}/eureka/
Run Code Online (Sandbox Code Playgroud)

但是,如果我只是将server.port更改为8787,那么任何服务都无法注册,甚至服务注册表本身也无法注册.

2017-01-09 16:18:21.584  WARN 17496 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure
2017-01-09 16:18:21.584  WARN 17496 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_SERVICES-REGISTRY/xxx.org:services-registry:8787 - registration failed Cannot execute request on any known server

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
...
2017-01-09 16:13:33.299  WARN 17496 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator …
Run Code Online (Sandbox Code Playgroud)

spring-cloud netflix-eureka

6
推荐指数
1
解决办法
1万
查看次数

无法执行目标com.spotify:docker-maven-plugin:0.4.3:build异常捕获:HttpHostConnectException:连接到localhost:2375

Spring Cloud使用以下docker代码部署项目pom.xml:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- tag::plugin[] -->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.3</version>
                <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory>${project.basedir}</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
            <!-- end::plugin[] -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

当我运行命令:时mvn package docker:build,它会抛出错误:

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.3:build (default) on project users-microservice: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused -> [Help 1]
[ERROR]
[ERROR] To …
Run Code Online (Sandbox Code Playgroud)

maven-3 docker spring-boot spring-cloud

6
推荐指数
1
解决办法
2299
查看次数

Spring Cloud Stream Kafka 多重绑定

我正在使用 Spring Cloud Stream Kafka 绑定器来消费来自 Kafka 的消息。我能够使我的示例与单个 Kafka Binder 一起工作,如下所示

spring:
  cloud:
    stream:
      kafka:
        binder:
          consumer-properties: {enable.auto.commit: true}
          auto-create-topics: false
          brokers: <broker url>
      bindings:
        consumer:
          destination: some-topic
          group: testconsumergroup
          consumer:
            concurrency: 1
            valueSerde: JsonSerde
        producer:
          destination: some-other-topic
          producer:
            valueSerde: JsonSerde
Run Code Online (Sandbox Code Playgroud)

请注意,此处两个绑定都指向同一个 Kafka Broker。但是,我遇到了一种情况,我需要发布到某个 Kafka 集群中的一个主题,并且还需要从不同 Kafka 集群中的另一个主题进行消费。我应该如何更改配置才能绑定到不同的 Kafka 集群?

我尝试过这样的事情

spring:
  cloud:
    stream:
      binders:
        defaultbinder:
          type: kafka
          environment:
            spring.cloud.stream.kafka.streams.binder.brokers: <cluster1-brokers>
        kafka1:
          type: kafka
          environment:
            spring.cloud.stream.kafka.streams.binder.brokers: <cluster2-brokers>
      bindings:
        consumer:
          binder: kafka1
          destination: some-topic
          group: testconsumergroup
          consumer:
            concurrency: 1
            valueSerde: JsonSerde …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud spring-cloud-stream spring-kafka spring-cloud-stream-binder-kafka

6
推荐指数
0
解决办法
9266
查看次数

仅为一个客户端创建 Feign 配置?

我有一大堆使用共享配置的 Feign 客户端(MyFeignConfiguration.class):

@FeignClient(name = "clientA", url = "http://serviceA.com", fallbackFactory = ServiceAFallbackFactory.class, configuration = MyFeignConfiguration.class)

@FeignClient(name = "clientB", url = "http://serviceB.com", fallbackFactory = ServiceBFallbackFactory.class, configuration = MyFeignConfiguration.class)

@FeignClient(name = "clientC", url = "http://serviceC.com", fallbackFactory = ServiceCFallbackFactory.class, configuration = MyFeignConfiguration.class)
Run Code Online (Sandbox Code Playgroud)

但是,对于新客户端,我想将用于 OkHttp 的底层 Http 客户端更改为 OkHttp。在MyFeignConfiguration课堂上,我可以添加以下内容:

@Configuration
class MyFeignConfiguration {
    @Bean
    public Client getClient() {
        return OkHttpClient() // use the OkHttp client 
    }
   
    @Bean
    public ErrorDecoder getErrorDecoder() {
        //... existing configs
    }
Run Code Online (Sandbox Code Playgroud)

然而,现在所有的客户端都在使用这个OkHttp客户端。如何配置新的 feign 客户端以便只有它使用 OkHttp 客户端?另外,我仍然需要使用 …

java rest spring spring-cloud feign

6
推荐指数
1
解决办法
9941
查看次数

Spring Cloud 配置服务器 GitHub SHA-1 错误

语境

\n

这是关于 Spring Cloud Config Server业余爱好项目(带有@EnableConfigServer)。

\n

昨天,可以开始申请了。

\n

今天,由于 Git 通信错误,应用程序无法启动。

\n

从GitHub 的官方博客文章中提到,从 2022 年 3 月 15 日开始,不再支持 SHA-1。这解释了我这两天得到的结果。

\n
\n

2022 年 3 月 15 日

\n

改变成为永久性的。

\n

我们\xe2\x80\x99将永久停止接受 DSA 密钥。在上述截止点之后上传的 RSA 密钥仅适用于 SHA-2 签名(但同样,在此日期之前上传的 RSA 密钥将继续适用于 SHA-1)。已弃用的 MAC、密码和未加密的 Git 协议将被永久禁用。

\n
\n

即使我没有删除现有的 SSH 密钥,今天仍然无法启动。但无论如何,现在存储库设置的“部署密钥”部分下的唯一密钥是 2022 年 3 月 15 日截止日期之后添加的 SSH 密钥。

\n
\n

依赖版本

\n

依赖管理:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n
依赖性版本
spring-cloud-依赖项霍克斯顿.SR12
\n
\n

依赖关系: …

spring github spring-cloud

6
推荐指数
1
解决办法
4998
查看次数

如何使用 Spring Cloud Stream 4.x 生产者和消费者来检测 Spring Boot 3.x 以关联记录器中的跟踪信息

升级到 Spring Boot 3 后,我必须更新跟踪/关联配置,以从 Spring Cloud Sleuth 切换到新的 Micrometer 跟踪库。

此时,我可以在日志中看到 traceId/spanId 信息,这些信息已使用带有自动检测的 .txt 文件的 HTTP 调用正确传输到其他服务WebClient。

然而,Spring Cloud Streams Kafka 生产者和消费者似乎没有被检测到。

这是生产者的示例:

logger.debug("Sending message to kafka queue {}", message)
streamBridge.send(bindingName, message)
Run Code Online (Sandbox Code Playgroud)

带有traceId、spanId的日志:

[producer,638b36642e4fe0b203b7f32b746b22de,03b7f32b746b22de] 52233 --- [ctor-http-nio-3] i.s.m.p.p.ProjectTaskEventProducer       : Sending message to kafka queue GenericMessage [xxx]
[producer,638b36642e4fe0b203b7f32b746b22de,03b7f32b746b22de] 52233 --- [ctor-http-nio-3] o.s.c.s.binder.DefaultBinderFactory      : Creating binder: kafka
Run Code Online (Sandbox Code Playgroud)

在消费者方面,我有这个简单的 KStream:

    @Bean
    fun processEvent() =
        Function<KStream<EventKey, EventValue>, KStream<EventKey, EventValue?>> { events ->
            events.process(
                ProcessorSupplier {
                    Processor<EventKey, EventValue, EventKey, EventValue> {
                        logger.info("{}", …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud spring-cloud-stream spring-kafka micrometer

6
推荐指数
1
解决办法
1959
查看次数