我有git的spring cloud配置服务器和客户端应用程序,其设置如下: 春季靴子:2.1.17-快照 java:1.8
服务器运行正常。
但是客户端无法获取服务器详细信息。
它引发以下错误: 无法解析值“ $ {rate}”中的占位符“ rate” 费率是属性的一部分。
服务器pom.xml:
public MainPage()
{
InitializeComponent();
webview.Navigating += Webview_Navigating;
}
private void Webview_Navigating(object sender, WebNavigatingEventArgs e)
{
var url = e.Url;
if (url.Contains("example.com"))
{
//...
}
}
服务器bootstrap.yaml:
<?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.1.17.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>m2-config-server-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>m2-config-server-2</name>
<description>config server 2 with git</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
这可以正确构建服务器,并且调用http:// localhost:8888 / s1rates / default可以正常工作。
但是客户端没有这样做。
客户端pom.xml:
---
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/hardik92/spring-cloudconfig-tolls
# username: uname
# password: pwd
search-paths:
- 'station*'
repos:
perf:
pattern:
- "*/perf"
uri: https://github.com/hardik92/spring-cloudconfig-tolls-perf
search-paths:
- 'station*'
客户端bootstrap.properties:
<?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.1.17.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>m2-config-client-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>m2-config-client-2</name>
<description>config client 2 with git</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
我看到了许多类似的问题,但是没有一个答案对我有帮助。由于没有足够的代表,我无法在此处发表评论或添加答案。
我在SpringBoot 2.4中尝试了相同的操作,但是发生了相同的错误。
任何帮助将不胜感激。
谢谢, 哈迪克
答案 0 :(得分:1)
此问题与Spring Boot不相关,但与Spring Cloud有关。有关Spring Cloud 2020.0.0-M5中重大更改的详细列表,请参见Spring Cloud 2020.0 Release Notes。
请特别注意指定默认情况下未启用引导程序的部分。启用它的一种方法是将以下Maven依赖项添加到项目POM文件中:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
这样,无论何时启动Spring Cloud配置服务器客户端,都应该看到它正确地从Spring Cloud配置服务器中获取了相关的属性值。实际上,您的控制台日志应指定以下事实:
2020-11-30 19:17:26.800 INFO 9891 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
无论如何,希望您到目前为止已经解决了这个问题;-)
答案 1 :(得分:0)
不穿衣服
spring.cloud.config.uri = http:// localhost:8888
到
spring.cloud.config.uri = http://127.0.0.1:8888
它适用于弹簧靴2.1.17.BUILD-SNAPSHOT。
但是sprint引导2.4.0-SNAPSHOT仍然失败。