1

我已经从 spring 的 initialzr 生成了一个 spring boot 配置服务器。

我已经用brew安装了rabbitmq。initialzr 使用引导版本2.1.1.RELEASE和云版本Greenwich.M3生成。

简单的休息服务正在连接到 rabbitmq 队列。配置服务器连接到 gitlab 配置存储库。

但是当我提交并推送更改时,服务应用程序不会反映更改。推送完成后,配置服务器会收到日志消息。谁能说什么可能是错的?rabbitmq 控制台中似乎没有出现任何消​​息。我已经能够通过执行器/总线刷新通过rabbitmq刷新属性。

config-server 在提交更改到 config-repo 的 employee-service.yml 文件时记录消息:

2018-12-07 11:53:12.185  INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint     : Refresh for: employee:service
2018-12-07 11:53:12.228  INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.253  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.259  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : Started application in 0.072 seconds (JVM running for 3075.606)
2018-12-07 11:53:12.345  INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []
2018-12-07 11:53:12.345  INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint     : Refresh for: employee-service
2018-12-07 11:53:12.377  INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.398  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.402  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : Started application in 0.056 seconds (JVM running for 3075.749)
2018-12-07 11:53:12.489  INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []

config-server 有这个 application.yml:

---

server:
  port: ${PORT:8888}

spring:
  cloud:
    bus:
      enabled: true
    config:
      server:
        git:
          uri: ${CONFIG_REPO_URI:git@gitlab.<somedomain>:<somegroup>/config-repo.git}
          search-paths:
          - feature/initial-repo

  main:
    banner-mode: "off"

和 ConfigServerApplication.java:

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

以及这些 gradle 依赖项:

dependencies {
    implementation('org.springframework.cloud:spring-cloud-config-server')
    implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
    implementation('org.springframework.cloud:spring-cloud-config-monitor')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
    implementation('org.springframework.cloud:spring-cloud-stream-test-support')
}

服务有这个 applciation.yml:

---
server:
  port: 8092

management:
  security:
    enabled: "false"

  endpoints:
    web:
      exposure:
        include: 
        - '*'

spring:
  main:
    banner-mode: "off"

  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

这个 bootstrap.yml:

---

spring:
  application:
    name: employee-service

  cloud:
    config:
      uri: 
      - http://localhost:8888
      label: feature(_)initial-repo

这些 gradle 依赖项:

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.cloud:spring-cloud-starter-config')
    implementation('org.springframework.cloud:spring-cloud-starter-bus-amqp')
    implementation('org.springframework.boot:spring-boot-starter-actuator')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

这个主要课程:

@SpringBootApplication
public class EmployeeServiceApplication {

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

和这个控制器类:

@RefreshScope
@RestController
public class WelcomeController {

    @Value("${app.service-name}")
    private String serviceName;

    @Value("${app.shared.attribute}")
    private String sharedAttribute;

    @GetMapping("/service")
    public String getServiceName() {
        return "service name [" + this.serviceName + "]";
    }

    @GetMapping("/shared")
    public String getSharedAttribute() {
        return " application.yml [" + this.sharedAttribute + "]";
    }
}
4

1 回答 1

1

尝试使用 Maven 而不是 Gradle 创建和构建您的项目。

我遇到同样的问题。我有两个具有相同 RabbitMQ 依赖项的相同应用程序,一个是使用 Maven 构建的,第二个是使用 Gradle 构建的。基于 Maven 的应用程序按预期将内容发布到 RabbitMQ。使用 Gradle 构建的同一个应用程序不会建立与 RabbitMQ 的连接,也不会发布事件。为了进一步说明问题,我使用 Spring Tools 在 Eclipse 中运行这两个应用程序。

于 2018-12-10T19:08:04.460 回答