gpt4 book ai didi

spring-cloud-config - Spring Cloud Config Basic Security 抛出 401 错误

转载 作者:行者123 更新时间:2023-12-04 08:04:22 24 4
gpt4 key购买 nike

我在服务器端有以下配置:

server:
port: 8888

spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: "classpath:/config"
security:
user:
name: test
password: test

并在客户端进行以下配置:
spring:
cloud:
config:
fail-fast: true
profile: "${spring.profiles.active}"
uri: "${SPRING_CLOUD_CONFIG_URI:http://localhost:8888/}"
username: test
password: test

我可以使用 user/pwd 从浏览器成功访问属性如 test/test ,但是当我的客户端尝试获取它时失败并出现 401 错误:
INFO 7620 --- [5cee934b64bfd92] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
WARN 7620 --- [5cee934b64bfd92] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 401 null

我尝试将 spring cloud 的日志级别设置为 DEBUG,但没有记录任何其他内容,所以我不知道为什么我从客户端获取 401,而我可以使用相同的凭据通过浏览器成功访问属性。

我还尝试从服务器和客户端中删除安全性,它运行得很好,这意味着其余的配置都很好。但问题是,当我应用基本安全性时,我忽略了什么,为什么它不起作用并抛出 401?

最佳答案

请检查您指定配置文件名称的方式是否正确,以及它是否在 Java 代码中正确解析。您可以实现 CommandLineRunner 并从 Environment 变量打印事件配置文件。

如果您指定了属性 spring.profiles.active 作为 pom.xml 中的 native ,您可以在 application/yaml 文件中将其解析为 @spring.profiles.active@

如果您将属性文件指定为 VM 参数,则它应该适用于当前实现。

如果您没有在 pom 或 VM 参数中指定 spring.profiles.active,它将解析为默认配置文件,而不是 native 配置文件。配置客户端和配置服务器中的配置文件应该相同。

关于spring-cloud-config - Spring Cloud Config Basic Security 抛出 401 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56336879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com