Search code examples
javaspring-securityjwttoken

How to include jwt secret in application.yaml for Java Spring


I am trying to set up the values for the security for jwt in a java application.

Normally in application.properties you could have:

security.jwt.secret= "something"
security.jwt.expiration-in-ms = "here you will set the ms"

What is the right/proper way of setting the jwt secret and expiration in application.yaml?

Currently I have:

security:
jwt:
secret: "jwt-tokens-that-should-be-changed-production"

I saw online that this is how you write de jwt secret in yaml, but for the expiration I saw different ways of doing it like using:

expiration: 608500

or

expire-length: 30000

But now I'm not sure if it's the correct way to set the jwt secret and expiration.

Also getting this enter image description here

But I do have it:

enter image description here


Solution

  • In yaml indentation is important. Indentation maintains the hierarchy in the file. So in your case, it should look like:

    security:
      jwt:
        secret: "jwt-tokens-that-should-be-changed-production"
    

    It's not important how many spaces you use for indentation, but you have to be consistent throughout the whole file.

    Not sure what is the question about expiration.