This question is already answered here: In Java, what is the simplest way to create an SSLContext with just a PEM file?
I have created a library for this use case to simplify the configuration. It uses bouncy castle under the covers. See below for the usage:
X509ExtendedKeyManager keyManager = PemUtils.loadIdentityMaterial("certificate-chain.cer", "mykey.key");
X509ExtendedTrustManager trustManager = PemUtils.loadTrustMaterial("mycer.cer");
SSLFactory sslFactory = SSLFactory.builder()
.withIdentityMaterial(keyManager)
.withTrustMaterial(trustManager)
.build();
SSLContext sslContext = sslFactory.getSslContext();
To use the above setup you can use this library:
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>sslcontext-kickstart-for-pem</artifactId>
<version>8.0.0</version>
</dependency>