title: Override default X509TrustManager in SpringBoot
body: <p>I am trying to use my DummyX509TrustManager with Springboot.</p>
  <p>In order to do that I write the following class:</p>
  <pre><code>@Configuration
  public class DummyComponent {
  
  @PostConstruct
  public void sslContextConfiguration() {
      try {
          SSLContext sslContext = SSLContext.getInstance(&quot;TLS&quot;);
          sslContext.init(null, new TrustManager[] { new DummyTrustManager() }, null);
          SSLContext.setDefault(sslContext);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  <p>It seems this doesn't have any effects on my code, because it's used the default X509TrustManagerImpl. Maybe I have to override it in another way?</p>
  <p><strong>SOLUTION:</strong></p>
  <pre><code>@Configuration
  public class MyConfig {
  
      @Bean
      public TomcatServletWebServerFactory containerFactory() {
          TomcatServletWebServerFactory  tomcat = new TomcatServletWebServerFactory ();
          tomcat.addAdditionalTomcatConnectors(createSslConnector());
          return tomcat;
      }
  
      private Connector createSslConnector() {
          Connector connector = new Connector(&quot;org.apache.coyote.http11.Http11NioProtocol&quot;);
          Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
          try {
              File keystore = new ClassPathResource(keystorepath).getFile();
              File truststore = new ClassPathResource(truststorepath).getFile();
              connector.setScheme(&quot;https&quot;);
              connector.setSecure(true);
              connector.setPort(port);
  
              protocol.setKeystoreFile(keystore.getAbsolutePath());
              protocol.setKeystorePass(keystorepassw);
              protocol.setKeyAlias(keystorealias);
              protocol.setSSLEnabled(true);
  
              protocol.setTruststoreFile(truststore.getAbsolutePath());
              protocol.setTruststorePass(truststorepassw);
              protocol.setClientAuth(Boolean.TRUE.toString());
  
              protocol.setTrustManagerClassName(&quot;pakage.DummyTrustManager&quot;);
  
              return connector;
          } catch (IOException ex) {
              throw new IllegalStateException(&quot;can't access keystore: [&quot; + &quot;keystore&quot;
                  + &quot;] or truststore: [&quot; + &quot;keystore&quot; + &quot;]&quot;, ex);
          }
      }
  }
  </code></pre>