【问题标题】:Unable to read property values using config-client app from PCF config server service无法使用 PCF 配置服务器服务中的配置客户端应用程序读取属性值
【发布时间】:2019-06-04 09:51:57
【问题描述】:

在我的 PCF 日志中,配置客户端应用程序提供 “ConfigServicePropertySourceLocator:找不到 PropertySource: 401未经授权”

我有 gitlab 存储库来在 PCF 配置服务器中提供属性文件。 如果我检查配置服务器 -> 管理 -> 它给出“ 配置服务器在线”

我在哪里缺少配置?

bootstrap.yml 配置客户端应用

spring:
  application:
    name: <config-client-name>
  cloud:
    config:
      enabled: true
      name: <config-server-instance-name>
      uri: <uri details from view credential modal>
#      username: <tried different permutations to get it working>
#      password: <tried different permutations to get it working>
management: 
  security: 
    enabled: false

manifest.yml 配置客户端应用

applications:
- name: <app-name>
  host: <app-name>
  memory: 1024M
  instances: 1
  path: /target/<app-name>-0.0.1-SNAPSHOT.jar
  buildpack: java_buildpack_offline
  services:
    - <pcf config server instance name>
  env:
    SPRING_PROFILES_ACTIVE: dev

我做了很多工作以获得一些结果,但没有运气,示例应用程序运行良好。 我已经使用 github 存储库尝试了我自己的配置服务器和配置客户端应用程序,并且成功了。

但是在 PCF 中我完全被卡住了,请帮忙。

【问题讨论】:

  • 您联系过 PCF 支持吗?
  • @spencergibb 不,我没有
  • a.) 尝试简化您正在做的事情。使用 SCS,您应该能够只使用在 boostrap.yml 中设置的 spring.application.name。很多东西对你来说是自动化的,所以现在删除其余的并尝试获得一个基线工作应用程序。 b.) 确保您遵循此处的说明 -> docs.pivotal.io/spring-cloud-services/2-0/common/config-server/… 并引入适当的 SCS 客户端依赖项。如果您无法使其正常工作,请从正在运行的示例应用程序开始,然后逐步在此基础上进行构建。这将有助于确定什么不起作用
  • 我知道我可能不需要 ma ifest.yml 中的大量细节。但是,如果我不提供详细信息,那么当应用程序在 pcf 上启动时,它会尝试在 localhost:8888 找到 comfig 服务器
  • 您是在使用 Pivotal 的 Spring Cloud Services (SCS) tile 提供的 Config Server,还是提供您的自定义?

标签: spring-boot gitlab spring-cloud cloud-foundry pcf


【解决方案1】:

您的配置看起来没有任何问题。如果您在 PCF 中看到配置服务器在线,则表示配置服务已正确初始化并可以使用。

但是,让我们尝试一下适合您的示例应用程序。

如果您正在使用 gradle build,请在 build.gradle 中添加以下信息(或相应地添加 pom.xml。)

  1. SCS(Spring Cloud services)(提及的版本与springBootVersion = '2.0.6.RELEASE'兼容,如果您使用的是不同版本的spring-boot,请检查可比性。)

    进口{

        mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:2.0.1.RELEASE"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Finchley.RELEASE"
    
     }
    
  2. 包括配置客户端依赖项

compile("io.pivotal.spring.cloud:spring-cloud-services-starter-config-client")

现在让我们转到bootstrap.yml: 只需以下信息即可选择属性

spring:
  application:
    name: <config-client-name>

如果您在推送到 PCF 时使用相同的活动配置文件,则无需更改 application.yml

【讨论】:

    【解决方案2】:

    @Avhi - 你的回答帮助了我。

    我的错误是我使用了错误的依赖项,并且添加了不必要的信息。在 bootstrap.yml

    spring:
      application:
        name: <config-client-name>
      cloud:
        config:
          enabled: true
          name: <config-server-instance-name>
          uri: <uri details from view credential modal>
    #      username: <tried different permutations to get it working> 
    #      password: <tried different permutations to get it working>
    management: 
      security: 
        enabled: false
    

    name: &lt;config-server-instance-name&gt; 我们应该配置我们将从客户端应用程序指向的属性文件名,我提供了配置服务器实例名称。 注意:我了解到我们可以指定多个用逗号分隔的属性文件。

    uri: <uri details from view credential modal>
    #      username: <tried different permutations to get it working> 
    #      password: <tried different permutations to get it working>
    

    以上三个属性都没用,我因此浪费了大部分时间。

    除非我们想在 localhost:8080 应用中绑定配置服务器服务,否则我们不需要设置这些值。

    在我们的 manifest.yml 中提供服务名称并没有什么坏处,因为它不是应用程序的一部分,所以不会造成任何麻烦。顺便说一句,我们可以使用 CLI 或 PCF App Manager Web 控制台来创建服务并将其绑定到我们的应用程序。

    设置好之后,我们可以期待spring security网页输入用户名和密码(显然我们不知道)。如果配置了 spring security 那么很好,或者我们可以在测试时禁用。

    我做了两件事来禁用和激活执行器的所有端点(因为我使用的是 spring-boot 2.x)

    添加的依赖如下:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-rsa</artifactId>
        <!-- <version>1.0.5.RELEASE</version> -->
    </dependency>
    

    并创建 SecurityConfiguration 以明确禁用安全性

    @Configuration
    @EnableWebSecurity
    public class SecurityConfiguration  extends WebSecurityConfigurerAdapter{
        @Override
        protected void configure(HttpSecurity http) throws Exception{
            http.csrf().disable();
            http.authorizeRequests().antMatchers("/").permitAll();
        }
    }
    

    为了使所有执行器端点都可以访问,我做了以下操作:

    management: 
      endpoints: 
        web: 
          exposure: 
            include: "*"
    

    【讨论】:

      猜你喜欢
      • 2021-09-12
      • 1970-01-01
      • 2019-03-21
      • 2019-07-22
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多