danvega / jwt

Spring Security + JWT
83 stars 37 forks source link

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

Open JavierMarcosAle opened 1 year ago

JavierMarcosAle commented 1 year ago

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 + ']';
    }

}
danvega commented 1 year ago

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