jwt icon indicating copy to clipboard operation
jwt copied to clipboard

Convert the record class to a normal class for use in Java 8

Open JavierMarcosAle opened this issue 2 years ago • 1 comments

Hi, I'm new to Java and Spring. I have the following problem and I hope your support. I would really appreciate it very much.

"Record" is not available in java 8, I have used intellij idea to do the conversion to a normal class and when executing the application it gives me the following error. (In java 17 it runs without any problem)

Parameter 0 of constructor in dev.danvega.jwt.config.RsaKeyProperties required a bean of type 'java.security.interfaces.RSAPublicKey' that could not be found.

How can I solve it?

Class:

@ConfigurationProperties(prefix = "rsa")
public final class RsaKeyProperties {
    private final RSAPublicKey publicKey;
    private final RSAPrivateKey privateKey;

    public RsaKeyProperties(RSAPublicKey publicKey, RSAPrivateKey privateKey) {
        this.publicKey = publicKey;
        this.privateKey = privateKey;
    }

    public RSAPublicKey publicKey() {
        return publicKey;
    }

    public RSAPrivateKey privateKey() {
        return privateKey;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || obj.getClass() != this.getClass()) return false;
        var that = (RsaKeyProperties) obj;
        return Objects.equals(this.publicKey, that.publicKey) &&
                Objects.equals(this.privateKey, that.privateKey);
    }

    @Override
    public int hashCode() {
        return Objects.hash(publicKey, privateKey);
    }

    @Override
    public String toString() {
        return "RsaKeyProperties[" +
                "publicKey=" + publicKey + ", " +
                "privateKey=" + privateKey + ']';
    }

}

JavierMarcosAle avatar Nov 10 '22 19:11 JavierMarcosAle

Depending on what version of SpringBoot you're on... you might need to add the @ConstructorBinding annotation to the class

https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/properties/ConstructorBinding.html

danvega avatar Nov 10 '22 19:11 danvega