簡體   English   中英

在 Tomcat/Spring Boot 上配置 SSL(“Could not find key store classpath:keystore.jks”錯誤)

[英]Configuring SSL on Tomcat/Spring Boot ("Could not find key store classpath:keystore.jks" error)

我正在嘗試配置 SSL。 Hover,我得到一個例外說

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Could not find key store classpath:keystore.jks

這是我的 application-https.properties 文件:

server.port = 8443
server.ssl.key-store = classpath:keystore.jks
server.ssl.key-store-password = secret
server.ssl.key-password = another-secret
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/postgres?currentSchema=myschema
spring.datasource.username=postgresql
spring.datasource.password=postgresql
spring.datasource.driverClassName=org.postgresql.Driver

我的應用程序.properties:

spring.profiles.active=https

我已經閱讀了有關 ssl 的文檔,但我不知道出了什么問題。 任何幫助將不勝感激。

確保您執行了以下操作:

  1. 將 .jks 文件放在 main/resources 中。
  2. 你運行了命令: mvn clean install

Keystore 不能從 Spring 以外的類路徑讀取。 (如果是 kafka,我們沒有任何選擇,kafka 總是希望位置在文件系統上而不是在 jar 文件中。)所以我建議使用下面的屬性並給出密鑰庫位置的絕對路徑。

應用程序.properties

spring.kafka.ssl.key-store-location=file:certificate.jks

在代碼中:

@Value("${spring.kafka.ssl.key-store-location}")
    private Resource keystoreLocation;

props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keystoreLocation.getFile().getAbsolutePath());

這樣您就可以讀取密鑰庫。 您可能需要將文件復制到文件系統而不是 Jar 中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM