title: How to solve "java.io.FileNotFoundException: class path resource cannot be resolved to URL" when trying to add ssl certificate?
body: <p>I am trying to add an existing SSL certificate(.cer) to a Spring boot application. Followed the following steps,</p>
  <p>Step 1: Converted the existing .cer certificate to .p12 certificate using the below command in keytool of JDK 8.</p>
  <pre><code>keytool -import -alias cert -file myCertificate.crt -keystore certificate.p12 -storepass password
  </code></pre>
  <p>Step 2 : Placed this certificate.p12 that was generated in &quot;resources&quot; folder of the application.</p>
  <p>Step 3 : Added the below configuration in &quot;application.properties&quot;</p>
  <pre><code>server.ssl.key-store = classpath:certificate.p12
  server.ssl.key-store-password=password
  server.ssl.key-store-type=pkcs12
  server.ssl.key-alias=cert
  server.ssl.key-password=password
  server.ssl.enabled=true
  server.port=8443  
  security.require-ssl=true
  </code></pre>
  <p>Step 4 : Added the below &quot;SecurityConfig.java&quot; file in application.</p>
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.requiresChannel().anyRequest().requiresSecure();
      }
  }
  </code></pre>
  <p>Step 5 : Added the below code in &quot;Application.java&quot;</p>
  <pre><code>@Bean
      public ServletWebServerFactory servletContainer() {
          TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
              @Override
              protected void postProcessContext(Context context) {
                  SecurityConstraint securityConstraint = new SecurityConstraint();
                  securityConstraint.setUserConstraint(&quot;CONFIDENTIAL&quot;);
                  SecurityCollection collection = new SecurityCollection();
                  collection.addPattern(&quot;/*&quot;);
                  securityConstraint.addCollection(collection);
                  context.addConstraint(securityConstraint);
              }
          };
          tomcat.addAdditionalTomcatConnectors(redirectConnector());
          return tomcat;
      }
  private Connector redirectConnector() {
          Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
          connector.setScheme(&quot;http&quot;);
          connector.setPort(80);
          connector.setSecure(false);
          connector.setRedirectPort(443);
          return connector;
      }
  </code></pre>
  <p>After adding all the above code and configuration changes. I am getting the below exception when I start the spring boot application - <code>Caused by: org.springframework.boot.web.server.WebServerException: Could not load key store 'classpath:certificate.p12' Caused by: java.io.FileNotFoundException: class path resource [certificate.p12] cannot be resolved to URL because it does not exist</code>. Kindly help to fix this issue. Thanks in advance!</p>