【问题标题】:Spring config server not starting with keystoreSpring 配置服务器未从密钥库开始
【发布时间】:2017-11-17 11:40:54
【问题描述】:

尝试使用密钥库启动 Spring Cloud 配置服务器,但在启动时得到以下信息:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'encryptionBootstrapConfiguration': Unsatisfied dependency expressed through field 'encryptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'textEncryptor' defined in org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$RsaEncryptionConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.crypto.encrypt.TextEncryptor]: Factory method 'textEncryptor' threw exception; nested exception is java.lang.NullPointerException

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'textEncryptor' defined in org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$RsaEncryptionConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.crypto.encrypt.TextEncryptor]: Factory method 'textEncryptor' threw exception; nested exception is java.lang.NullPointerException    

Caused by: java.lang.NullPointerException: null
        at org.springframework.cloud.context.encrypt.EncryptorFactory.create(EncryptorFactory.java:34) ~[spring-cloud-context-1.1.9.RELEASE.jar:1.1.9.RELEASE]

以下选项用于启动组件:

--spring.cloud.config.server.git.uri=http://mygit.com/alexander.lovett/service-discovery-demo.git
--spring.cloud.config.server.git.searchPaths=Software/config
--spring.rabbitmq.host=spring-bus
--management.security.enabled=false
--encrypt.keystore.location=file://C:/Users/607567487/BTTV/workspace/service-discovery-demo/Software/config-serverserver.jks
--encrypt.keystore.secret=changeme
--encrypt.keystore.password=letmein
--encrypt.keystore.alias=mytestkey

我已经尝试将位置设置为file://C:/.../server.jksfile:C:/.../server.jks,甚至将 jks 放在类路径中并尝试classpath:server.jks

但无论如何仍然会出现相同的错误。

我的依赖:

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-server</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-tomcat</artifactId>
      <scope>provided</scope>
    </dependency> 
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-monitor</artifactId>
    </dependency>
  </dependencies>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Camden.SR7</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.8.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

【问题讨论】:

    标签: spring encryption config keystore


    【解决方案1】:

    简单的修复...

    属性应该是encrypt.key-store.* 而不是encrypt.keystore.*

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,但原因不同。这是一个简短的description。简而言之,问题是由ENCRYPT_KEY 环境变量引起的,该变量触发了textEncryptor bean autoconfig 和格式错误的KeyProperties。 Spring 无法从环境变量ENCRYPT_KEY 填充KeyProperties,导致NullPointerException。如果加密密钥作为系统属性-Dencrypt.key=123 提供,那么spring 配置textEncryptor bean 将没有问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-13
        • 2016-06-26
        • 2019-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-26
        • 2023-02-06
        相关资源
        最近更新 更多