title: Spring Boot / Jetty + SSL: Keystore not found (FileNotFoundException)
body: <p>I am trying to enable SSL with embedded jetty in a Spring Boot Application. </p>
  
  <p><strong>Spring Boot Starter Version: 2.1.0.RELEASE</strong></p>
  
  <p><strong>My configuration:</strong></p>
  
  <p>I created a <strong>keystore</strong> with the following command:</p>
  
  <pre><code>keytool -genkey -keyalg RSA -alias webapp -keystore keystore.jks -storepass password -keysize 2048
  </code></pre>
  
  <p>The resulting keystore.jks file was placed in <code>src/main/resources/ssl</code>.</p>
  
  <p>The tutorials mostly say that referencing this keystore in the <strong>application.yaml</strong> should be enough to "make it work":</p>
  
  <pre><code>server:
      port: 9292
      servlet:
          context-path: /
      ssl:
          key-store: classpath:keystore.jks
          key-store-password: password
          key-alias: webapp
          key-store-type: JKS
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <p>When I try to start the application, it fails:</p>
  
  <pre><code>Caused by: org.springframework.boot.web.server.WebServerException: Could not find key store 'classpath:keystore.jks'
  at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSslKeyStore(SslServerCustomizer.java:195) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSsl(SslServerCustomizer.java:164) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.customize(SslServerCustomizer.java:73) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.customizeSsl(JettyServletWebServerFactory.java:195) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:145) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  ... 13 common frames omitted
      Caused by: java.io.FileNotFoundException: class path resource [keystore.jks] cannot be resolved to URL because it does not exist
  at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
  at org.springframework.boot.web.embedded.jetty.SslServerCustomizer.configureSslKeyStore(SslServerCustomizer.java:190) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
  ... 19 common frames omitted
  </code></pre>
  
  <p>When I look into the maven target directory though, the keystore.jks is placed under classes/ssl, so it should be in the classpath, right?</p>
  
  <p>Can someone point out what I am missing? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Strangely enough, moving the keystore.jks to <code>src/main/resources</code> seems to fix the problem. Why jetty able to find the keystore there, but not in the subdirectory <code>src/main/resources/ssl</code>?</p>