我会使用 spring-cloud-bus 来刷新配置应用程序。目前我的工作失败了。似乎配置与旧版本不完全相同。 在我的配置服务器 pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>my.app.configuration-server</groupId>
<artifactId>configuration-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>configuration-server</name>
<description>Configuration server for services</description>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.4.21</kotlin.version>
<spring-cloud.version>2020.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
...
在服务器配置 application.yml
spring:
application:
name: configuration-server
cloud:
config:
server:
git:
uri: git@github.com:myrepository/myApplicationsConfig.git
clone-on-start: true
default-label: master
health: false
enabled: true
bus:
enabled: true
profiles:
active: development
rabbitmq:
host: rabbitIP
port: rabbitPort
username: username
password: password
virtual-host: /
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registryFetchIntervalSeconds: 5
在应用程序中进行配置
pom:( 父级的spring boot和spring cloud依赖版本相同)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.app.to.configure</groupId>
<artifactId>app-to-configure</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
<groupId>my.app.to.configure</groupId>
<artifactId>web-application</artifactId>
<name>web-application</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>
...
</dependencies>
...
在 application.yml 中:
spring:
application:
name: my-application-to-configure
cloud:
config:
discovery:
enabled: true
service-id: configuration-server
profile: development
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registryFetchIntervalSeconds: 5
目前,当我在 github 上更新配置时,webhook 调用 configuration-server 但我有 400 错误。在配置服务器日志中,我有:
Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required List parameter 'path' is not present]
我不明白什么是“路径”。你能给我一些帮助吗?谢谢。